Python Practice › Tuple Programs › Program 1
Tuple of pairs from two lists
Write a Python program to create a tuple of pairs from two lists.
Input
[4, 6, 8], [7, 1, 4]
Output
((4, 7), (6, 1), (8, 4))
Approach
zippairs items at the same position;tuple()collects the pairs.
Solution
list1 = [4, 6, 8]list2 = [7, 1, 4]print(tuple(zip(list1, list2)))Output
((4, 7), (6, 1), (8, 4))
Line by line
Line 3
zip yields (4, 7), (6, 1), (8, 4); tuple() stores them in a tuple.
Learn the concept
New to this topic? Read the lesson, then come back.