Flatten..with less recursion

Martin von Loewis loewis at informatik.hu-berlin.de
Sun May 27 08:25:14 EDT 2001


"Nick Perkins" <nperkins7 at home.com> writes:

> def flatten(L):
>     if type(L) != type([]): return [L]
>     if L == []: return L
>     return reduce(lambda L1,L2:L1+L2,map(flatten,L))
[...]
> ...maybe someone knows how to avoid the lambda,

Sure: Use operator.add.

Regards,
Martin




More information about the Python-list mailing list