do you master list comprehensions?

aleks90210 at aleks90210 at
Fri Dec 17 07:55:43 EST 2004

Thought you might enjoy my super-small flatten function: (though google
groups seems to be munging my whitespace today)

def flatten(d):
return reduce(lambda a,b:a+b,[(type(x) in (list, tuple) \
and flatten(x) or [x]) for x in d])

More information about the Python-list mailing list