Why are tuples immutable?
steve at holdenweb.com
Wed Dec 15 16:53:05 CET 2004
Antoon Pardon wrote:
> Op 2004-12-15, Roel Schroeven schreef <rschroev_nospam_ml at fastmail.fm>:
>>Antoon Pardon wrote:
>>>Op 2004-12-15, Fredrik Lundh schreef <fredrik at pythonware.com>:
>>>>sorry, but I don't understand your reply at all. are you saying that dictionaries
>>>>could support mutable keys (e.g lists) by making a copy of the key? how would
>>>>such a dictionary pick up changes to the original key object? (I'm talking about
>>>>the key stored in the dictionary, not the key you're using to look things up).
>>>You want to mutate a key that is within a dictionary?
>>No, we don't want to mutate it; as far as I know, that is exactly the
>>reason why dictionaries don't support mutable keys.
> And I think that is a stupid reason. There are enough other situations
> were people work with mutable objects but don't wish to mutate specific
> objects. Like objects in a sorted sequence you want to keep that way
> or objects in a heapqueue etc.
> Demanding that users of dictioanaries somehow turn their mutable objects
> into tuples when used as a key and back again when you retrieve the keys
> and need the object can IMO ibe a bigger support nightmare than the
> possibility that code mutates a key in a dictionary.
So provide your objects with a __hash__ method, and you can use them as
Sheesh, learn Python already. What a troll. [Plonk]
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
Holden Web LLC +1 703 861 4237 +1 800 494 3119
More information about the Python-list