Python中的list和iterator有什么区别?

我正在阅读这本书想想Python:如何像计算机科学家一样思考,表示在Python 3.x中, dict([元组列表])返回迭代器而不是一个列表(如Python 2.7中的情况)。

I am reading the book Think Python: How to think like a computer scientist, which says that in Python 3.x, dict([list of tuples]) returns an iterator instead of a list (as is the case in Python 2.7).

本书没有进一步解释,让我感到困惑。特别是,我想知道:

The book did not explain it any further, which has left me confused. In particular, I would like to know:


  1. 迭代器和列表如何不同,

  1. How are iterators and lists different, and

在列表上返回迭代器有什么好处?

What is the advantage of returning an iterator over a list?




 1 条回答