Why are tuples immutable?

Antoon Pardon apardon at forel.vub.ac.be
Thu Dec 16 03:44:49 EST 2004


Op 2004-12-15, Steve Holden schreef <steve at holdenweb.com>:
> 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 
> dictionary keys.
>
> Sheesh, learn Python already. What a troll. [Plonk]
>

Let me get this straight.

You first say dictionaries don't support mutable keys for some reason.

I say I find it a stupid reason.

Then you mark me a troll because I don't know the language while at
the same time making a suggestion that implies your original remark
about python was wrong.

-- 
Antoon Pardon



More information about the Python-list mailing list