I\'m wondering if there is a quick and easy way to output ordinals given a number in python.
For example, given the number 1, I\'d like to output
I had to convert a script over from javascript where I had a useful fn that replicated phps date obj. Very similar
def ord(n):
return str(n)+("th" if 4<=n%100<=20 else {1:"st",2:"nd",3:"rd"}.get(n%10, "th"))
this tied in with my date styler:
def dtStylish(dt,f):
return dt.strftime(f).replace("{th}", ord(dt.day))
ps -I got here from another thread which was reported as a duplicate but it wasn't entirely since that thread also addressed the date issue