question about subclassing dict
Russell E. Owen
owen at astrono.junkwashington.emu
Tue Feb 5 13:00:21 EST 2002
In article <mailman.1012873998.10011.python-list at python.org>,
"Delaney, Timothy" <tdelaney at avaya.com> wrote:
>> From: Russell E. Owen
>>
>> I'm writing a subclass of dict (OrderedDict, keeps items in the order
>> entered; you can get it from http://www.astro.washington.edu/owen/ if
>> interested.).
>
>I would prefer to call this a "ChonologicalDict" or "ChronoDict" to better
>describe the order that it stores things.
>
>"OrderedDict" implies that the objects will come out in the order that you
>would get by calling sort() on a list.
I would call that a SortedDict. I've contemplated writing one, but have
not found a use for it yet. (In contrast, I've been wanting an ordered
dictionary -- or chronological if you prefer -- for a long time. Now
that I have it, I can go back and clean up some of my existing code
quite nicely.)
In general, I wish Python had a more complete set of collection classes
(like Smalltalk). Writing OrderedDict was not all that difficult, but
there were a lot of finicky details to get right and I'm not sure even
now that it offers the full dictionary interface.
-- Russell
P.S. I uploaded a few more improvements as of today. Keys() was
returning the internal list instead of a copy, and I made all the iter
methods depend on iterkeys(), for less reliance on internal details and
easier subclassing. I plan to stop messing with it now and start using
it.
More information about the Python-list
mailing list