Why are there no ordered dictionaries?
Carsten Haese
carsten at uniqsys.com
Wed Nov 23 08:36:41 EST 2005
On Tue, 2005-11-22 at 20:44, Tom Anderson wrote:
> On Tue, 22 Nov 2005, Carsten Haese wrote:
>
> > On Tue, 2005-11-22 at 14:37, Christoph Zwerschke wrote:
> >
> >> In Foord/Larosa's odict, the keys are exposed as a public member which
> >> also seems to be a bad idea ("If you alter the sequence list so that it
> >> no longer reflects the contents of the dictionary, you have broken your
> >> OrderedDict").
> >
> > That could easily be fixed by making the sequence a "managed property"
> > whose setter raises a ValueError if you try to set it to something
> > that's not a permutation of what it was.
>
> I'm not a managed property expert (although there's a lovely studio in
> Bayswater you might be interested in), but how does this stop you doing:
>
> my_odict.sequence[0] = Shrubbery()
It would only break if the getter returns the internal list directly.
The getter should return a copy instead, which is what the keys() method
already does anyway. This would ensure that the only way to alter the
sequence is by replacing it in its entirety.
-Carsten.
More information about the Python-list
mailing list