"number-in-base" ``oneliner''

Andrea Griffini agriff at tin.it
Mon Nov 1 09:52:28 CET 2004


On Mon, 01 Nov 2004 07:21:09 GMT, Andrea Griffini <agriff at tin.it>
wrote:

>This is a bit shorter ...
>
>roman = lambda x: "".join(["".join(map(lambda c: "IVXLCDM"[ord(c) -
>ord("A")+2*N], "/A/AA/AAA/AB/B/BA/BAA/BAAA/AC".split("/")[x//10**N %
>10])) for N in (3, 2, 1, 0)])

No idea why I initially thougt about using ASCII codes... this
is simpler and shorter...

roman = lambda x: "".join(["".join(map(lambda c: "IVXLCDM"[int(c)
+2*N],"/0/00/000/01/1/10/100/1000/02".split("/")[x//10**N % 10]))
for N in (3, 2, 1, 0)])

Andrea




More information about the Python-list mailing list