Some thougts on cartesian products

Jean-Paul Calderone exarkun at divmod.com
Sun Jan 22 21:54:57 EST 2006


On Mon, 23 Jan 2006 03:21:59 +0100, Christoph Zwerschke <cito at online.de> wrote:
>
>BTW: What is the shortest way to get the binary representation of a
>number in Python? Is there really not something like itoa() anywhere in
>the standard libs?

I'm somewhat partial to this implementation:

binary = lambda i,c = (lambda i,c: i and (c(i>>1, c) + str(i&1)) or ''): c(i,c)

Although I won't claim it is the best solution.

Fortunately for you, I guess, it looks like Python 2.5 will have either a bin() builtin or a '%b' format character or something like that in order to do this.

Jean-Paul



More information about the Python-list mailing list