What does ZIP do in Python
The zip()
function returns a zip object, which is an iterator of tuples where the first item in each passed iterator is paired together, and then the second item in each passed iterator are paired together, etc.
If the passed iterators have different lengths, the iterator with the least items decides the length of the new iterator.
Syntax: zip(iterator1, iterator2, iterator3 ...)
>>> a = (1, 2, 3, 4) >>> b = ("abc") >>> x = zip(a,b) >>> x <zip object at 0x0000027B20EB8480> >>> list(x) [(1, 'a'), (2, 'b'), (3, 'c')] >>>
Subscribe
Login
Please login to comment
0 Discussion