Iterating multiple lists at a time

I was writing a python script,I needed to iterate multiple iterator. At first I was planning to loop through each of the item.But I found it really non-pythonic. So I went through python docs to figure out if I can find something to get this code more pythonic.We can iterate iterator mainly two ways using zip() and using itertools.izip

from itertools import izip
A = [1, 2]
B = [3, 4]
C = [5, 6]
def iterate_using_zip(item1, item2, item3):
for a,b,c in zip(item1, item2, item3):
print a,b,c
def iterate_using_izip(item1, item2, item3):
for k,l,m in izip(item1, item2, item3):
print k,l,m
if __name__=='__main__':
iterate_using_izip(A, B, C)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.