Ordered Dictionary 0.2.1

Fuzzyman fuzzyman at gmail.com
Sun Dec 18 16:01:41 CET 2005

There is a new version of `odict
<http://www.voidspace.org.uk/python/odict.html>`_ - the ordered

**What Is It ?**

This module provides two classes ``OrderedDict``, and
``SequenceOrderedDict``. The ordered dictionary is a dictionary-like
object (actually a subclass of the normal dictionary data type) that
keeps keys in insertion order.

This means it has all the normal dictionary methods. Methods that would
normally return values in an arbitrary order are now ordered.

You can specify and alter the order, through the setkeys method.

Because an ordered dictionary is something like a sequence, it also has
several sequence methods. The SequenceOrderedDict allows you to act on
the keys, values, and items directly - as if they were sequences. This
is convenient if you want to treated your object more like a sequence
than a dictionary.

**What Has Changed ?**

This is a major change since the *0.1.0* series. ``OrderedDict`` now
has several sequence methods - including allowing slicing, slice
assignment, and slice deletion.

.. note::

    ``OrderedDict`` *is* compatible with Python 2.2. Slicing isn't -
mainly because you can't index a seqeuence with a slice object in
Python 2.2.

It also has a subclass called ``SequenceOrderedDict`` that has custom,
callable sequence-like objects, for ``items``, ``keys``, and
``values``. You can call them liek the methods they replace, or act on
them directly as sequences to change the contents of your dictionary.

*Other changes:*

    You can now test for equality and inequality with objects (except
for dictionaries for which it is undefined). This allows you to do
tests like : ::

        OrderedDict() == False

    Added the ``strict`` keyword, which raises a ``ValueError`` if you
do slice assignment with keys that are already in the dictionary.

    Assignment to keys in ``SequenceOrderedDict`` is now only for
re-ordering the keys.

    Fixed bug where slice assignment to keys could lose information.
(and optimised by slicing ranges to get the indexes we are assigning to
instead of indexing each key).

    You change ``keys``, ``items``, and ``values`` through new methods
``setkeys``, ``setitems``, and ``setvalues`` methods.

    Minor changes, thanks to Christoph Zwerschke for suggestions.

    Added ``__deepcopy__`` method (previously deepcopy failed).

    Changed use of slice to types.SliceType for Python 2.2.

    Fixed bugs in ``__getattr__`` and popitem

    Optimisation in ``OrderedDict.__init__`` when creating an instance
from an ``OrderedDict``.

    Implemented new ``__repr__``.

    Version 0.2.0

    Added index to ``OrderedDict.popitem``

    Implemented ``SequenceOrderedDict``, which has keys, items, values
as custom, callable, sequence objects.

    By Michael Foord - from suggestions on comp.lang.python

    Hidden the ``sequence`` attribute

    Implemented slicing (including deleting a slice and assigning to a

    Implemented sequence methods ``sort``, ``reverse``, ``insert``,

More information about the Python-announce-list mailing list