convert loop to list comprehension

bvdp at bvdp at
Sat Sep 9 02:40:09 CEST 2006

Paul Rubin wrote:
> bearophileHUGS at 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