On this page
  1. zip
  2. Import & Availability
  3. Overview & Signature
  4. Usage
  5. Gotchas
  6. REPL Inspect

zip

Prev: vars | Up: __builtins__
Rel: all, any, enumerate, filter, iter
Ref: docs.python.org — zip
Tags: #public #python3 #builtins


Import & Availability

# Built-in (available globally without import)
from builtins import zip

Overview & Signature

zip(*iterables, strict=False)

The zip object yields n-length tuples, where n is the number of iterables passed as positional arguments to zip(). The i-th element in every tuple comes from the i-th iterable argument to zip(). This

Usage

names = ["Ada", "Grace"]
scores = [98, 100]
assert list(zip(names, scores)) == [("Ada", 98), ("Grace", 100)]
# Unzip with zip(*pairs)
a, b = zip(*[("Ada", 98), ("Grace", 100)])
assert a == ("Ada", "Grace") and b == (98, 100)

Gotchas

REPL Inspect

help(zip)

Linked from

Related notes