Skip to content

Instantly share code, notes, and snippets.

@alukach
Created May 3, 2014 01:31
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 alukach/10ef410f6264f0a1aec6 to your computer and use it in GitHub Desktop.
Save alukach/10ef410f6264f0a1aec6 to your computer and use it in GitHub Desktop.
from collections import OrderedDict
import inflect
p = inflect.engine()
ORDINAL_NUMBER_MAP = OrderedDict()
for i in range(1, 300): # Highest avenue in New York is 271st
word_form = p.number_to_words(i) # 1 -> 'one'
ordinal_word = p.ordinal(word_form) # 'one' -> 'first'
ordinal_number = p.ordinal(i) # 1 -> '1st'
ORDINAL_NUMBER_MAP[ordinal_word] = ordinal_number # 'first': '1st'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment