When is it better to use zip instead of izip?

后端 未结 4 472
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 22:22

When is it better to use zip instead of itertools.izip?

4条回答
  •  不知归路
    2020-11-28 23:06

    The itertools library provides "iterators" for common Python functions. From the itertools docs, "Like zip() except that it returns an iterator instead of a list." The I in izip() means "iterator".

    Python iterators are a "lazy loaded" sequence that saves memory over regular in-memory list. So, you would use itertools.izip(a, b) when the two inputs a, b are too big to keep in memory at one time.

    Look up the Python concepts related to efficient sequential processing:

    "generators" & "yield"
    "iterators"
    "lazy loading"
    

提交回复
热议问题