# Create two sample lists x = [1, 2, 3] y = [10, 20, 30]
# Use zip to get item pairs merged = zip(x, y)
# Print out the merged list print(list(merged))
[(1, 10), (2, 20), (3, 30)]
The Python zip function gets two lists as output. Then, the function starts extracting one item from each list. The pairs of items will be inserted in tuples and the tuples. Therefore, the output is a list of tuples.
Note: For zip to work, the two input lists should have the same number of items.
Python Mega Course: Learn Python in 60 Days, Build 20 Apps
Learn Python on Udemy completely in 60 days or less by building 20 real-world applications from web development to data science.