Skip to content

Instantly share code, notes, and snippets.

@dongkwan-kim
Created November 20, 2017 05:53
Show Gist options
  • Save dongkwan-kim/30e4c4867ce2106a2ab673a5343fea20 to your computer and use it in GitHub Desktop.
Save dongkwan-kim/30e4c4867ce2106a2ab673a5343fea20 to your computer and use it in GitHub Desktop.
Make cardinal number to ordinal number in python3
import math
ordinal = lambda n: "%d%s" % (n,"tsnrhtdd"[(math.floor(n/10)%10!=1)*(n%10<4)*n%10::4])
# source: https://stackoverflow.com/questions/9647202/ordinal-numbers-replacement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment