[Python-3000] How much should non-dict mappings behave like dict?

skip at pobox.com skip at pobox.com
Fri Sep 12 19:13:11 CEST 2008


    >> select key from dict order by key
    >> select value from dict order by key

    Guido> What's the purpose of the "order by key" clauses here? Doesn't
    Guido> that force the return order? Perhaps you meant to leave those
    Guido> out?

It's simply to guarantee that the order of the elements of values() is the
same as the order of the elements of keys().  Again, I was thinking that
this property: zip(d.keys(), d.values()) == d.items() was a desirable
property of mappings, not just of the CPython dict implementation.

So is there a definition of what it means to be a mapping?  Maybe this page
in the C API doc?

    http://docs.python.org/api/mapping.html

>From that I infer that a mapping must offer these methods: keys, values,
items, __len__, __contains__, __getitem__, __setitem__ and __delitem__.  No
guarantee about the ordering of keys, values and items is made.  Can we
settle on something like this and spell it out explicitly somewhere in the
3.0 docs?

Skip


More information about the Python-3000 mailing list