Skip to content

Instantly share code, notes, and snippets.

@rehatpsingh
Created October 27, 2020 13:08
Show Gist options
  • Save rehatpsingh/403e04c3b46623d256687776132f02d3 to your computer and use it in GitHub Desktop.
Save rehatpsingh/403e04c3b46623d256687776132f02d3 to your computer and use it in GitHub Desktop.
6.5 Write code using find() and string slicing (see section 6.10) to extract the number at the end of the line below. Convert the extracted value to a floating point number and print it out.
BEST TIME COMPLEXITY METHOD
text = "X-DSPAM-Confidence: 0.8475";
atpos=text.find('0')
print(atpos)
sspos=text.find(' ',atpos)
print(sspos)
host=text[atpos : sspos]
print(float(host))
OR
text = "X-DSPAM-Confidence: 0.8475";
Pos = text.find(':')
req = text[Pos+1:]
print(float(req))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment