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
1
Fixed for negative-inputs, based on eric.frederich's nice sol'n (just added abs when using %):
abs
%
def ordinal(num): return '%d%s' % (num, { 11: 'th', 12: 'th', 13: 'th'}.get(abs(num) % 100, { 1: 'st',2: 'nd',3: 'rd',}.get(abs(num) % 10, 'th')))