Why are tuples immutable?

Antoon Pardon apardon at forel.vub.ac.be
Wed Dec 22 10:00:03 CET 2004

Op 2004-12-22, Fredrik Lundh schreef <fredrik at pythonware.com>:
> Antoon Pardon wrote:
>>> and to temporarily refer back to the top of this thread, do all this without
>>> any performance impact, compared to the current implementation.
>> Why should that be? This originated when someone argued that lists could
>> easily be resorted and reheapified.
> from the original post (by someone else):
>     The way I see it is that if we enable __setitem__ for tuples there
>     doesn't seem to be any performance penalty if the users don't use it
>     (aka, python performance independent of tuple mutability).

The thread above (more than one '>')  was a tangents and this particular
tangent originated when someone wrote that my analogy with (the invariants of)
sorted lists and heaps was not a good one because they could be repaired easily.
So here we were talking about performace costs for a repair.

> to which you later added:
>     The performace gained by using tuples as keys in dictionaries is
>     entirely illusional.
> etc.  am I the only one one this list that can hold more than one post in my
> head and chew gum at the same time?

But this was another subthread. The argument here was about performance
gain because by having immutable keys, the dictionary wouldn't need to
make a copy when inserting a new key. The counter argument was that
it made more copying needed outside the dictionary code.

So you may be able to hold more than one post in your had, but you
seem unable to distinghuis the arguments in each.

Antoon Pardon

More information about the Python-list mailing list