Tuple of pairs from two lists

EasyTuple Programs · 1 of 70

Write a Python program to create a tuple of pairs from two lists.

Advertisement
Input
[4, 6, 8], [7, 1, 4]
Output
((4, 7), (6, 1), (8, 4))

Approach

  1. zip pairs items at the same position; tuple() collects the pairs.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More tuple programs

← All 70 Tuple Programs