3 ms·
Love it. It's that way with range, too, right? Does one end up casting things to lists more often if so much is naturally an iterator?
by textminer 14y ago
Love it. It's that way with range, too, right? Does one end up casting things to lists more often if so much is naturally an iterator?
- pyre 14y agohttp://www.python.org/dev/peps/pep-3106/ http://www.python.org/dev/peps/pep-3106/ The original plan was to simply let .keys(), .values() and .items() return an iterator, i.e. exactly what iterkeys(), itervalues() and iteritems() return in Python 2.x. However, the Java Collections Framework [1] suggests that a better solution is possible: the methods return objects with set behavior (for .keys() and .items()) or multiset (== bag) behavior (for .values()) that do not contain copies of the keys, values or items, but rather reference the underlying dict and pull their values out of the dict as needed.