Combining Iterables into Tuples with zip Function

  • Share this:

Code introduction


The zip function combines multiple iterable objects into tuples and returns them. If the number of arguments is different, the shorter iterable objects will be repeated until the longest iterable object is traversed.


Technology Stack : Built-in library

Code Type : Built-in library functions

Code Difficulty :


                
                    
def zip(*iterables):
    """
    将可迭代对象组合成元组并返回。
    """
    iterator = iter(iterables)
    return zip(*iterator)