How to Zip Two Lists into Pairs in Python

Combine two lists element-wise into a list of tuples using Python's built-in zip() function.

Easy Python 3.9+ Aug 9, 2026 Lists & loops 14 views 0 copies

Python code

9 lines
Python 3.9+
def zip_lists_into_pairs(list1, list2):
    pairs = list(zip(list1, list2))
    return pairs

if __name__ == "__main__":
    fruits = ["apple", "banana", "cherry"]
    quantities = [3, 5, 2]
    result = zip_lists_into_pairs(fruits, quantities)
    print(result)

Output

stdout
[('apple', 3), ('banana', 5), ('cherry', 2)]

How it works

The zip() function takes two or more iterables and returns an iterator of tuples, where the i-th tuple contains the i-th element from each iterable. Wrapping it with list() materializes the iterator into a list, which is easier to inspect and use later. If the lists have different lengths, zip stops at the shortest one, so no extra elements are silently dropped. This pattern is common for pairing data that belongs together, like names with counts or keys with values.

Common mistakes

  • Forgetting to wrap zip() in list() and printing the iterator object instead of the pairs.
  • Assuming zip() pads missing elements when lists have different lengths — it truncates to the shortest.
  • Expecting zip() to work with non-iterable objects like integers.

Variations

  1. Use `dict(zip(list1, list2))` to create a dictionary from the pairs.
  2. Use a list comprehension with `zip` to transform pairs, e.g., `[(k, v) for k, v in zip(keys, values)]`.

Real-world use cases

  • Pairing user IDs with their corresponding scores from separate lists for reporting.
  • Combining column headers with row values to build a dictionary for CSV-like data.
  • Matching product names with their stock counts for inventory display.

Sponsored

Run this sample

Open the browser IDE to tweak the example and see results without installing anything.

Open editor

More from Lists & loops

Related tutorials and quizzes for this topic.