Skip to content

Instantly share code, notes, and snippets.

@phrz
Created August 17, 2012 21:00
Show Gist options
  • Save phrz/3382623 to your computer and use it in GitHub Desktop.
Save phrz/3382623 to your computer and use it in GitHub Desktop.
Returns an English Ordinal Number.
def ordinal(number):
suffix="th"
ones=int(str(number)[-1])
tens=0
if number/10 >= 1:tens = int(str(number)[-2])
if tens != 1:
special = {1:"st",2:"nd",3:"rd"}
try:
suffix = special[ones]
except:
pass
return str(number)+suffix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment