Dictionary .keys() and .values() should return a set [with Python3000 in mind]

Terry Reedy tjreedy at udel.edu
Sun Jul 2 16:14:15 EDT 2006


The meaning of dict.keys, etc, will not change for the 2.x series.  For 
3.0, I believe that Guido already intends that .keys() no longer return a 
separate list.  For one thing, a major, if not the main use, of the method 
is for iteration, as in 'for keys in d.keys():'.  For this, creating and 
them discarding a separate list is inefficient and, in a sense, silly.

One option is to make .keys be what .iterkeys is today.  Another, more 
recent, is to make .keys return a new iterable dict view object, details 
not yet worked out.  Either way, one would make an independent set or list 
with set(d.keys()) or list(d.keys)).

Terry Jan Reedy






More information about the Python-list mailing list