Python style.

Jacek Generowicz jmg at ecs.soton.ac.uk
Wed May 10 03:50:53 EDT 2000


How would you rewrite the following code, in good
python style ?

list1 = [ 1,2,3,4,5,6 ]
list2 = [ 6,5,4,3,2,1 ]

count = 0
for item in list1:
    print item - list2[count]
    count = count + 1

In other words, I want to loop through two lists,
performing some operation on elements in
corresponding positions . . . there must be a more
elegant way.

Thanks,

Jacek





More information about the Python-list mailing list