Why are tuples immutable?

Fredrik Lundh fredrik at pythonware.com
Mon Dec 13 11:04:02 EST 2004


"jfj" wrote:

> Why can't we __setitem__ for tuples?

http://www.python.org/doc/faq/general.html#why-are-there-separate-tuple-and-list-data-types

> 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).

how would you implement a dictionary where the keys could change, without
any performance penalty compared to the current implementation?

> On the other hand, right now we have to use a list if we want to
> __setitem__ on a sequence. If we could use tuples in the cases where
> we want to modify items but not modify the length of the sequence,
> programs could be considerably faster.

really?  in what way are tuples faster than lists?  have you noticed that "a[i]"
is actually faster if "a" is a list?  (especially in 2.2 and earlier).

</F> 






More information about the Python-list mailing list