Combining Iterables into Tuples with Iterator

  • Share this:

Code introduction


The function combines elements from multiple iterables into tuples and returns them as an iterator.


Technology Stack : Built-in library

Code Type : Function

Code Difficulty : Intermediate


                
                    
def zip(*iterables):
    """Combine elements from multiple iterables into tuples and return them as an iterator."""
    iters = list(iterables)
    while iters:
        yield tuple(iters[i] for i in range(len(iters) if iters[i] is not None else 0))