Created
September 8, 2018 15:48
-
-
Save Oziabr/461eca9e1dd757ba8d0fd77c0732cf8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
d = { v: i for i, v in enumerate('zero one two three four five six seven eight nine ten eleven twelve thirteen'.split())} | |
d.update({v+'teen': i+10 for v, i in d.items() if 3 < i < 10}) | |
d.update({'fifteen': 15, 'eighteen': 18}) | |
d.update({v: (i+2)*10 for i, v in enumerate('twenty thirty forty fifty sixty seventy eighty ninety'.split())}) | |
def parse_int(s): | |
if 'million' in s: return 1E6 | |
s = s.replace('thousand', '|').replace('and ', '').replace('-', ' ').replace('hundred', '-') | |
keys =[[sum([ d[k] for k in x.strip().split()]) for x in a.split('-')[::-1]] for a in s.split('|')[::-1]] | |
return sum([sum([100**j*1000**i*a for j, a in enumerate(b)]) for i, b in enumerate(keys)]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment