Skip to content

Instantly share code, notes, and snippets.

@JadeGrey
Created November 23, 2023 22:01
Show Gist options
  • Save JadeGrey/8e0b70ef19d7c5118a18f00a60c0da69 to your computer and use it in GitHub Desktop.
Save JadeGrey/8e0b70ef19d7c5118a18f00a60c0da69 to your computer and use it in GitHub Desktop.
adds an ordinal to a defined number
def ordinal(n):
suffix = ['th', 'st', 'nd', 'rd', 'th'][min(n % 10, 4)]
if 11 <= (n % 100) <= 13:
suffix = 'th'
return str(n) + suffix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment