Skip to content

Instantly share code, notes, and snippets.

@milo0
Created December 3, 2017 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milo0/fae12f5d29294bc7bef72d6daef8d29c to your computer and use it in GitHub Desktop.
Save milo0/fae12f5d29294bc7bef72d6daef8d29c to your computer and use it in GitHub Desktop.
Extract numeric values from a string
def extract_integers(string):
extracted_ints = [int(s) for s in string.split() if s.isdigit()]
return extracted_ints
def extract_floats(string):
floats = []
for s in string.split():
try:
extracted_floats.append(float(s))
except ValueError:
pass
return extracted_floats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment