问题
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