Monday, January 2, 2012

Python - How can I iterate through two lines?

You want the zip function.

a = [1,2,3]
b = ['a','b','c']
for
(n,l) in zip(a, b):
print "num: ", n ,"; let: ", l



num: 1 ; let: a
num: 2 ; let: b
num: 3 ; let: c

No comments:

Post a Comment