[Python-checkins] r64329 - peps/trunk/pep-0372.txt
armin.ronacher
python-checkins at python.org
Tue Jun 17 11:13:43 CEST 2008
Author: armin.ronacher
Date: Tue Jun 17 11:13:43 2008
New Revision: 64329
Log:
PEP 0372: added notice on comparing
Modified:
peps/trunk/pep-0372.txt
Modified: peps/trunk/pep-0372.txt
==============================================================================
--- peps/trunk/pep-0372.txt (original)
+++ peps/trunk/pep-0372.txt Tue Jun 17 11:13:43 2008
@@ -118,7 +118,8 @@
>>> d.byindex(2)
('foo', 'bar')
- If there is no key for index an `IndexError` is raised.
+ If there is no key for index an `IndexError` is raised. Slices are not
+ supported.
``odict.index(key)``
Returns the index of a key. If the key does not exist, a `ValueError` is
@@ -138,6 +139,17 @@
``odict.__reverse__()``
Supports reverse iteration by key.
+``odict.__eq__()`` / ``odict.__ne__()``
+ Compares the odict to another object. If it's compared to another
+ odict the ordering of items is taken into account, otherwise only
+ the keys and values.
+
+``odict.__cmp__()``
+ Ordered dicts are sorted by their items. ``cmp(od1, od2)`` is
+ equivalent to ``cmp(od1.items(), od2.items())`` if both ``od1``
+ and ``od2`` are ordered dicts. Otherwise the regular dict comparison
+ kicks in.
+
Questions and Answers
=====================
@@ -179,6 +191,20 @@
>>> odict(l)
collections.odict([('a', 42), ('x', 0), ('b', 23), ('c', 19)])
+Is the ordered dict a dict subclass?
+
+ Yes. Like ``defaultdict``, ``odict`` subclasses ``dict``.
+
+Does ``odict.pop()`` support list-like popping of items?
+
+ No. Neither ``odict.__getitem__()`` nor ``odict.pop()`` support
+ retrieving or deleting items by index. Slices are not supported
+ either. This would introduce ambiguities if integers or slice
+ objects are used as dict keys.
+
+ As a matter of fact, ``odict`` does not implement the ``Sequence``
+ interface.
+
Example Implementation
======================
More information about the Python-checkins
mailing list