You can download this code by clicking the button below.
This code is now available for download.
This function takes multiple iterable objects and returns an iterator of tuples, where each tuple contains elements from each input iterable.
Technology Stack : Built-in function
Code Type : Function
Code Difficulty : Intermediate
def zip(*iterables):
"zip(*iterables) --> zip object"
"see: zip(object) for constructor"
iterables = map(iter, iterables)
sentinel = object()
for iterable in iterables:
if len(iterable) == 0:
yield []
continue
first = sentinel
for element in iterable:
if first is sentinel:
first = element
yield [first]
else:
yield first + (element,)