sorteddict [was a PEP proposal, but isn't anymore!]

Duncan Booth duncan.booth at invalid.invalid
Mon Oct 1 08:51:12 EDT 2007


"Hamilton, William " <whamil1 at entergy.com> wrote:

>> From: thebjorn
>> What's stabledict? I'm assuming that ordereddict is a mapping that
>> maintains insertion order(?)
> 
> Yes, ordereddict is a dict that maintains insertion order.  Stabledict
> is probably a dict that maintains _an_ order, so that repr() and the
> like return the same value when used on dicts containing the same data.

Yes, that was what I was suggesting in an unclear manner: stabledict would 
be a dictionary which returned the same repr for the same contents no 
matter what order the elements were inserted.

>> In the Smalltalk collection hierarchy SortedCollection is a subclass
>> of OrderedCollection, which implies to me that it'd be better to add
>> an ordereddict first.
> 
> That depends entirely on how ordereddict and sorteddict function.  If
> they are similar there might be a benefit.  However, an ordereddict
> would probably be best implemented with an internal list of keys,
> whereas the consensus seems to be using a tree for sorteddict.  In this
> case, trying to build sorteddict from ordereddict is going to give you
> extra baggage and overhead for no benefit.
> 
Subclassing doesn't have to imply a common implementation, just a common 
interface.



More information about the Python-list mailing list