map/filter/reduce/lambda opinions and background unscientific mini-survey
Paweł Sakowski
pawel at sakowski.pl
Thu Jul 7 11:08:31 EDT 2005
Tom Anderson wrote:
> def flatten(ll):
> return reduce(lambda a, l: a.extend(l), ll, [])
>
> How would one do that as a list comp, by the way? I'm really not very good
> with them yet.
Not really a list-comprehension based solution, but I think what you want is
>>> ll=[[1,2],[3,4,5],[6]]
>>> sum(ll,[])
[1, 2, 3, 4, 5, 6]
--
Paweł Sakowski <pawel at sakowski.pl>
More information about the Python-list
mailing list