[Python-3000] PEP 3106: Revamping dict.keys(), .values() and .items()

Talin talin at acm.org
Wed Dec 20 08:16:53 CET 2006


Guido van Rossum wrote:
> I've written a quick version of PEP 3106, which expresses my ideas
> about how the dict methods to access keys, values and items should be
> redone.
> 
> The text is in svn:
> http://svn.python.org/view/peps/trunk/pep-3106.txt?rev=53096&view=markup
> 
> At some point it will appear on python.org: http://python.org/dev/peps/pep-3106/
> 
> Comments please? (Or we can skip the comments and go straight to the
> implementation stage. Patch anyone?)

Comments:

1) values() should be documented as list-like rather than set-like. (Or 
better yet bag-like, but Python doesn't have bags. In other words, it's 
really an unordered collection of items with no special indexing 
semantics or uniqueness constraint.)

My reasoning is that generally people don't expect to be able to do set 
membership tests of the values of a mapping; Mostly, values() is used 
for iteration. And given that all of the set-like operations are slow, 
let's just cut to the chase and say that values() isn't a set at all.

2) Names for d_keys, et al:

   -- map_keys_view
   -- map_values_view
   -- map_keys_values_view or map_items_view

Essentially, its a class that can take any map, and provide a view of 
its keys / values / etc.

Alternatively, we could stick them in a module called 'mapview' and call 
them:

   -- mapview.keys
   -- mapview.values
   -- mapview.items

-- Talin



More information about the Python-3000 mailing list