Producing multiple items in a list comprehension

Joel Koltner zapwireDASHgroups at yahoo.com
Thu May 22 16:53:16 EDT 2008


"inhahe" <inhahe at gmail.com> wrote in message 
news:5PjZj.78772$%15.70394 at bignews7.bellsouth.net...
> i figured out a solution
>
> sum([x,2*x] for x in range(4)],[]) #not tested

Nice... thanks; I probably had seen code using 'sum' to flatten but hadn't 
actually understood how it worked.  After playing around some it's now 
clear...

(Add one more opening bracket to your solution to make the interpreter 
happy -- I know you know this and it was missed only due to not actually 
trying it ought)

---Joel





More information about the Python-list mailing list