db3l at fitlinxx.com
Tue Jan 18 17:36:47 EST 2005
Antoon Pardon <apardon at forel.vub.ac.be> writes:
> Op 2005-01-18, Simon Brunning schreef <simon.brunning at gmail.com>:
> > On 18 Jan 2005 07:51:00 GMT, Antoon Pardon <apardon at forel.vub.ac.be> wrote:
> >> 3 mutating an item in a sorted list *does* *always* cause problems
> > No, it doesn't. It might cause the list no longer to be sorted, but
> > that might or might no be a problem.
> Than in the same vain I can say that mutating a key in a dictionary
> doesn't always cause problems either. Sure it may probably make a
> key unaccessible directly, but that might or might not be a problem.
Well, I'd definitely consider an inaccessible key as constituting a
problem, but I don't think that's a good analogy to the list case.
With the dictionary, the change can (though I do agree it does not
have to) interfere with proper operation of the dictionary, while a
list that is no longer sorted still functions perfectly well as a
list. That is, I feel "problems" are more guaranteed with a
dictionary since we have affected base object behavior, whereas sorted
is not an inherent attribute of the base list type but something the
application is imposing at a higher level.
For example, I may choose to have an object type that is mutable (and
not worthy for use as a dictionary key) but maintains a logical
ordering so is sortable. I see no problem with sorting a list of such
objects, and then walking that list to perform some mutation to each
of the objects, even if along the way the mutation I am doing results
in the items so touched no longer being in sorted order. The act of
sorting was to provide me with a particular sequence of objects, but
aside from that fact, the list continues to perform perfectly well as
a list even after the mutations - just no longer delivering objects in
More information about the Python-list