Iterate Through Two Lists in Parallel Python Using itertools.zip_longest()

(Last Updated On: 28/03/2023)

Python Program to Iterate Through Two Lists in Parallel Using itertools.zip_longest()

# Iterate Through Two Lists in Parallel itertools.zip_longest() in python

# Python program to iterate
# over 3 lists using itertools.zip_longest

import itertools

num = [1, 2, 3]
color = ['red', 'while', 'black']
value = [123, 456]

# iterates over 3 lists and till all are exhausted
for (a, b, c) in itertools.zip_longest(num, color, value):
	print (a, b, c)

Output:

1 red 123
2 while 456
3 black None

Leave a Reply

Your email address will not be published. Required fields are marked *