I feel stoopid ... this code is to verbose
Gerson Kurz
gerson.kurz at t-online.de
Fri Jun 14 13:15:25 EDT 2002
Correct me if I'm wrong, but all of the previous suggestions only seem
to insert dots, not dots and commas; i.e. you want the output like
this:
>>> 42.034.539.823,94
not
>>> 4.203.453.982.394
so here is my one liner:
strfmt = lambda x:"".join(map(lambda c,l,y=len(x):(l==3) and c+"," or
(not (l-3)%3 and c+"." or c),list(x),range(len(x),0,-1)))
print strfmt("4203453982394")
>>> 42.034.539.823,94
Of course, the statement in the above code should be written in one
line.
More information about the Python-list
mailing list