Python zip() Function

Returns an iterable object of tuples that joins together two or more iteratable objects, pairing each item in the iterables. The iterable with the least items determines the length of the tuple.

Syntax

Python
zip(iterator1, iterator2,...)

Parameters

ParameterDescription
iterator1, iterator2,... Required. A list of iterators that will be joined together

Example

Python
list1 = range(1, 5)
list2 = map(lambda x: x * 10, list1)
zipped = zip(list1, list2)
print(zipped)

# The zip() function is often used with list() to convert the object into a list.
print(list(zipped))

Output

<zip object at 0x000001380DDE5F88>
[(1, 10), (2, 20), (3, 30), (4, 40)]