Flatten a two-level list --> one liner?
Paul Rubin
http
Wed Mar 7 20:41:26 EST 2007
"Sergio Correia" <sergio.correia at gmail.com> writes:
> 2) Reduce
> eggs = reduce(lambda x, y: x+y, spam)
>
> I feel the 1st way is too cumbersome (three lines), and although I
> like the 2nd way (except for the lambda part), I understand reduce is
> discouraged by Guido so I want to know if there is a "Better Way"(TM)
> ?
I thought map/reduce were considered ok again, but the above runs
in quadratic time, not good.
I'd use:
eggs = list(itertools.chain(*spam))
More information about the Python-list
mailing list