flatten a level one list

bonono at gmail.com bonono at gmail.com
Thu Jan 12 04:23:20 EST 2006


Robin Becker wrote:
> Paul Rubin wrote:
> > Paul Rubin <http://phr.cx@NOSPAM.invalid> writes:
> >
> >>>>>import operator
> >>>>>a=[(1,2),(3,4),(5,6)]
> >>>>>reduce(operator.add,a)
> >>
> >>(1, 2, 3, 4, 5, 6)
> >
> >
> > (Note that the above is probably terrible if the lists are large and
> > you're after speed.)
> yes, and it is all in C and so could be a contender for the speed champ.
> I guess what you're saying is that it's doing
>
That is what I thought too but seems that [x for pair in li for x in
pair] is the fastest on my machine and what is even stranger is that if
I use psyco.full(), I got a 10x speed up for this solution(list
comprehension) which is head and shoulder above all the other suggested
so far.




More information about the Python-list mailing list