I learned that I can write like this. I used 2.7.11, but I wonder if 3 is the same.
items = [1, 2, 3, 4, 5]
pairs = [('aaa', 100), ('bbb', 200) ,('ccc', 300), ('ddd', 400), ('fff', 500)]
for key, value in pairs:
print key, value
#>>>
#aaa 100
#bbb 200
#ccc 300
#ddd 400
#fff 500
for item, pair in zip(items, pairs):
print item, pair[0], pair[1]
#>>>
#1 aaa 100
#2 bbb 200
#3 ccc 300
#4 ddd 400
#5 fff 500
for item, (key, value) in zip(items, pairs):
print item, key, value
#>>>
#1 aaa 100
#2 bbb 200
#3 ccc 300
#4 ddd 400
#5 fff 500
Recommended Posts