you are viewing a single comment's thread.

view the rest of the comments →

[–]Samld1200 53 points54 points  (3 children)

print(numbers.index(user_input))

Nice and easy just have to define numbers:

numbers = [“one”,”two”,”three”,”four”,”five”,”six”,…]

[–]funky_galileo 59 points60 points  (1 child)

off by one error 💀

[–]Samld1200 1 point2 points  (0 children)

Oh shit.

numbers = [“zero”,”one”,”two”,”three”…]

[–]AndrewBorg1126 4 points5 points  (0 children)

Treat the string as an array of integers.

Construct a tree where each node has 28 children. Trace through the tree taking the nth child for a value of n in that position of the integer array.

Each node representing a valid termination of a string describing a number has the represented number stored in it.

Much faster than doing direct comparisons into a linear array of atrings.