Python one-liner of the day
This is a function that takes an integer and returns its ordinal representation, e.g. “1st” for 1 and so on.
It’s not the most readable thing, but once I saw the pieces falling into place I couldn’t help myself. Repetition of the “th” literal is the only thing that bugs me. Oh well.
ord_text = lambda n: "%d%s" % (n, "th" if 10 < n % 100 < 14 else {1:"st", 2:"nd", 3:"rd"}.get(n % 10, "th"))
Comes with a one-line test suite!