[Tutor] Recursion and List Comprehensions

R. Alan Monroe amonroe at columbus.rr.com
Sat Oct 29 02:41:59 CEST 2005


> Unfortunately, I don't understand how list comprehensions work and how to
> implement them.  Can someone point me in the right direction, please.   

 
Compare these two pieces of code


x=[1,2,3,4]
y=[]
for eachnum in x:
    y.append(eachnum * 2)


versus

x=[1,2,3,4]
y = [each * 2 for each in x]



Try them both on your box :^)

Alan



More information about the Tutor mailing list