When are immutable tuples *essential*? Why can't you just use lists *everywhere* instead?
Neil Cerutti
horpner at yahoo.com
Mon Apr 23 14:21:41 EDT 2007
On 2007-04-23, Steve Holden <steve at holdenweb.com> wrote:
> Neil Cerutti wrote:
>> So the question becomes: Why do Python dictionaries require
>> keys to be of an immutable type?
>
> Because otherwise people would expect to be able to use a list
> to select a dictionary entry even after they'd modified
> elements of the list after creating the dictionary entry. Which
> they couldn't. So Python doesn't let them use lists.
The interpreter explains it: "A list is not a hashable object."
Choosing a hash table instead of some kind of balanced tree seems
to be just an optimization. ;)
--
Neil Cerutti
More information about the Python-list
mailing list