简体   繁体   English

Python Zip Function 的时间复杂度

[英]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))? zip(A,B) 和 list(zip(A,B)) 的时间复杂度是多少?

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的时间复杂度只是单个 function O(1) 并且将其包装在list是提供的最小可迭代对象的线性 O(n)。

zip returns a generator object that while iterated over supplies the next value for all supplied iterables as a tuple until one is exhausted. zip返回一个生成器 object ,它在迭代时为所有提供的可迭代对象提供下一个值作为元组,直到一个被耗尽。

list consumes the iterablereturning a list of all it's results. list使用 iterable,返回所有结果的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM