Problem splitting a string

Kent Johnson kent37 at tds.net
Sat Oct 15 09:28:03 EDT 2005


Alex Martelli wrote:
> Using sum on lists is DEFINITELY slow -- avoid it like the plague.
> 
> If you have a list of lists LOL, DON'T use sum(LOL, []), but rather
> 
> [x for x in y for y in LOL]

Should be
 >>> lol = [[1,2],[3,4]]
 >>> [x for y in lol for x in y]
[1, 2, 3, 4]

The outer loop comes first.

Kent



More information about the Python-list mailing list