Re: howto print binary number

2008-05-07 Thread Joel Bender
Python 3.0 has such a formatting operation, but Python 2.x does not. However it's not hard to write. Indeed. Refraining from using named lambdas: >>> def bin(x): ... return ''.join(x & (1 << i) and '1' or '0' for i in ... range(7,-1,-1)) ... >>> bin(12) '00

Re: Extended List Comprehension

2006-01-20 Thread Joel Bender
> You could (in 2.5) use: > >[(x if x%2 else 'even') for x in '1234'] Or this: [int(x)&1 and x or 'even' for x in '1234'] -- http://mail.python.org/mailman/listinfo/python-list

Shell-like Decorators

2006-01-18 Thread Joel Bender
I was inspired by shell-like processing mentioned here: and created a decorator version below. I've been using it for parsing a pile of C include files and building digraphs of the results. For example, given jdir('*.h') retu