Skip to content

Instantly share code, notes, and snippets.

@komuw
Created August 28, 2017 12:52
Show Gist options
  • Select an option

  • Save komuw/cdb18fedc803dff1ffafab30ce495c90 to your computer and use it in GitHub Desktop.

Select an option

Save komuw/cdb18fedc803dff1ffafab30ce495c90 to your computer and use it in GitHub Desktop.
extract numbers from string
str = "h3110 23 cat 444.4 rabbit 11 2 dog"
numbers = [int(s) for s in str.split() if s.isdigit()]
sum_of_numbers = sum(numbers)
print "sum_of_numbers:", sum_of_numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment