<[email protected]> wrote

Ideally, I'd be able to write:

for num in list1:
newlist.append(num+nextnum)

This doesn't work, though because there's no way to access "nextnum" unless I implement a "count" variable like this:

Or use an iterator:

L = [1,2,3,4,5,6]
i = iter(L)
L2 = [n+i.next() for n in i]
L2
[3, 7, 11]

Is that what you want?


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to