flatten a level one list
bonono at gmail.com
bonono at gmail.com
Wed Jan 11 20:50:34 EST 2006
Robin Becker wrote:
> Is there some smart/fast way to flatten a level one list using the
> latest iterator/generator idioms.
>
> The problem arises in coneverting lists of (x,y) coordinates into a
> single list of coordinates eg
>
> f([(x0,y0),(x1,y1),....]) --> [x0,y0,x1,y1,....] or
>
> g([x0,x1,x2,......],[y0,y1,y2,....]) --> [x0,y0,x1,y1,....]
>
> clearly if f is doable then g can be done using zip. I suppose this is a
> special case flatten, but can flatten be done fast? The python recipes
> seem rather slow compared to the builtin functions.
how fast is fast ?
for this case, is the following good enough ?
def flat(li):
for x,y in li:
yield x
yield y
More information about the Python-list
mailing list