python 3 中的可迭代对象和列表有什么区别?
What's the difference between an iterable and a list in python 3?
在幕后,可迭代对象不就是列表吗?使用 map
filter
list
等包装器有什么用?作为 filter
的东西实际上告诉你什么,除了它的起源?什么时候(除了在例如列表理解中更短)x
比 list(x)
更好,其中 x
是可迭代的?
我听说的一件事是将 map
和 filter
保留为可迭代对象比将它们用作列表更快。为什么是这样?使迭代更快的幕后有什么区别?
iterable 和 list 之间的区别就像花和玫瑰之间的区别。
所有的玫瑰都是花,但不是所有的花都是玫瑰。
所有列表都是可迭代的,但并非所有可迭代都是列表。
iterable
An object capable of returning its members one at a time. Iterables include all sequences type (like list, str, and tuples).
List 是一个可迭代的,并且有一些其他更具体的特征要列出。
检查一下:https://docs.python.org/3.5/glossary.html 尤其是可迭代部分。
在幕后,可迭代对象不就是列表吗?使用 map
filter
list
等包装器有什么用?作为 filter
的东西实际上告诉你什么,除了它的起源?什么时候(除了在例如列表理解中更短)x
比 list(x)
更好,其中 x
是可迭代的?
我听说的一件事是将 map
和 filter
保留为可迭代对象比将它们用作列表更快。为什么是这样?使迭代更快的幕后有什么区别?
iterable 和 list 之间的区别就像花和玫瑰之间的区别。
所有的玫瑰都是花,但不是所有的花都是玫瑰。
所有列表都是可迭代的,但并非所有可迭代都是列表。
iterable
An object capable of returning its members one at a time. Iterables include all sequences type (like list, str, and tuples).
List 是一个可迭代的,并且有一些其他更具体的特征要列出。
检查一下:https://docs.python.org/3.5/glossary.html 尤其是可迭代部分。