How do pythonistas print a number as words, like the equivalent of the Common Lisp code:
[3]> (format t \"~r\" 1e25)
nine septillion, nine hundred and nin
Here as a way to do it:
def abbreviate(x):
abbreviations = ["", "K", "M", "B", "T", "Qd", "Qn", "Sx", "Sp", "O", "N",
"De", "Ud", "DD"]
thing = "1"
a = 0
while len(thing) < len(str(x)) - 3:
thing += "000"
a += 1
b = int(thing)
thing = round(x / b, 2)
return str(thing) + " " + abbreviations[a]
It does this:
>>> abbreviate(11423)
11.43 K