Skip to content

Instantly share code, notes, and snippets.

@iam-py-test
Created July 4, 2021 21:40
Show Gist options
  • Save iam-py-test/d0aef3a4bf193d36dd2e22bc868d2465 to your computer and use it in GitHub Desktop.
Save iam-py-test/d0aef3a4bf193d36dd2e22bc868d2465 to your computer and use it in GitHub Desktop.
Turn strs into nums
numnames = {
"one":1,
"two":2,
"three":3
}
def strtonum(string):
try:
return int(string)
except:
try:
return numnames[string.lower()]
except:
return 0
import strtonum
print(strtonum.strtonum("1"))
print(strtonum.strtonum("one"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment