convert loop to list comprehension

bvdp at xplornet.com bvdp at xplornet.com
Fri Sep 8 20:40:09 EDT 2006


Paul Rubin wrote:
> bearophileHUGS at lycos.com writes:
> > print sum( ([i]*n for i,n in enumerate(seq)), [])
>
> Wow, I had no idea you could do that.  After all the discussion about
> summing strings, I'm astonished.

Me too ... despite what bearophile said, this is faster than the 2nd
example. Nearly as fast as the original loop :)




More information about the Python-list mailing list