zip(*iterables, strict=False) |
Returns test |
iteerables | ?? |
strict | ?? |
REMARKS |
* No prefix required - Core * Iterate over several iterables in parallel, producing tuples with an item from each one. * More formally: zip() returns an iterator of tuples, where the i-th tuple contains the i-th element from each of the argument iterables. * Another way to think of zip() is that it turns rows into columns, and columns into rows. This is similar to transposing a matrix. * zip() is lazy: The elements won't be processed until the iterable is iterated on, e.g. by a for loop or by wrapping in a list. * By default, zip() stops when the shortest iterable is exhausted. It will ignore the remaining items in the longer iterables, cutting off the result to the length of the shortest iterable: * zip() is often used in cases where the iterables are assumed to be of equal length. In such cases, it's recommended to use the strict=True option. Its output is the same as regular zip(): |
>>> for item in zip([1, 2, 3], ['sugar', 'spice', 'everything nice']):
print(item)
(1, 'sugar')
(2, 'spice')
(3, 'everything nice')
© 2025 Better Solutions Limited. All Rights Reserved. © 2025 Better Solutions Limited Top