how to flatten one level of list of lists?

soumitri soumitri at postmark.net
Wed May 30 18:01:26 CEST 2001


> George Young <gry at ll.mit.edu> wrote:
> : I have a list like:
> :   l = [[2], [3], [5], [11]]
> : and I want to get:
> :   ll = [2, 3, 5, 11]
> 
> Short but silly solution:
> 
>   ll = map(max,l)


How about this ?

l=[[1,2,2],[2],[2,3]]
ll=[ j for i in l for j in i ]

cheers,
Soumitri.





More information about the Python-list mailing list