You are here : python_3Built-in Functionszip

zip() - Built-in Functions

Make an iterator that aggregates elements from each of the iterables.


Syntax

zip(*iterables)


Example

def zip(*iterables):
    # zip('ABCD', 'xy') --> Ax By
    sentinel = object()
    iterators = [iter(it) for it in iterables]
    while iterators:
        result = []
        for it in iterators:
            elem = next(it, sentinel)
            if elem is sentinel:
                return
            result.append(elem)
        yield tuple(result)


Output / Return Value


Limitations


Alternatives / See Also


Reference