Search code examples
pythonziptime-complexity

Time Complexity for Python Zip Function


A = [1,2,3] B = ["a","c","d"]

What is the time complexity for zip(A,B) and list(zip(A,B))?


Solution

  • The time complexity of zip is just a single function O(1) and wrapping it in list is linear O(n) of the smallest iterable supplied.

    zip returns a generator object that while iterated over supplies the next value for all supplied iterables as a tuple until one is exhausted.

    list consumes the iterablereturning a list of all it's results.