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

Duncan Booth duncan.booth at invalid.invalid
Sat Sep 29 13:13:46 EDT 2007


thebjorn <BjornSteinarFjeldPettersen at gmail.com> wrote:

> On Sep 29, 4:23 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> [...]
>> Another example would be if you had a library which serialised a
>> dictionary to xml. There is nothing wrong with the library if it
>> doesn't care about order, but if you have some other reason why you
>> want the xml to be stable (e.g. because you store it in a version
>> control system and want to compare revisions) then a sorteddict would
>> allow you to impose that behaviour on the library from outside.
>>
>> Contrary to my earlier insistence that sorteddict is only really
>> useful if you can have a key parameter, both of these examples simply
>> want an arbitrary but defined order of iteration for dictionary keys.
>> A much simpler sorteddict that has been discussed earlier would be
>> sufficient. 
> 
> In fact, a dictionary that maintains insertion order would work in
> this case too.
> 
It would be better than the current situation, but say I have elements 'a', 
'b', and 'c'. Next run of the program I delete 'b', then the run after that 
I add 'b' back into the list so now I might get 'a', 'c', 'b'. Sorting 
would ensure that I can tell that I actually reverted a change.

Right now I think there are probably three dict variants needed: sorteddict 
(still waiting for a convincing use case), ordereddict (lots of use cases), 
and this one: stabledict.



More information about the Python-list mailing list