Difference between zip() functions in Python 2 and Python 3 [duplicate]

大城市里の小女人 提交于 2021-02-16 16:23:46

问题


I was wondering what the difference is between the zip() function in python 2 and python 3 is. I noticed when using the timeit module on both functions that the python 3 function was a lot faster. Thanks so much in advance :)


回答1:


Difference between Python 2 and Python 3 is Python 3 returns an iterators. Idea of this saving memory.




回答2:


In Python 3, the zip() function returns an iterator, meaning that you can only exhaust elements once, whereas Python 2 returns an iterable itself.

see here: Python 2 Doc, Python 3 Doc



来源:https://stackoverflow.com/questions/49746487/difference-between-zip-functions-in-python-2-and-python-3

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!