On 2007-04-23, Chris Cioffi <[EMAIL PROTECTED]> wrote: > On 23 Apr 2007 17:19:15 +0200, Neil Cerutti <[EMAIL PROTECTED]> > wrote: >> So the question becomes: Why do Python dictionaries require >> keys to be of an immutable type? > > Dictionary keys are hashed values. If you change the key, you > change the hash and lose the pointer to the referenced object.
Other dictionary-like implementations (C++ std::map for example) simply exhort you not to change keys (C++ makes it hard to ignore the exhortation) or suffer undefined behavior. Perhaps avoiding a cause of undefined behavior was the Python reason for the requirement. > Or: Because. ;-) Heh, heh. I was wondering, if we dig deep enough, wether we'll end up back at, "just an optimization," as the reason. -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list