Chris Angelico <ros...@gmail.com>: > On Thu, Nov 26, 2015 at 7:27 PM, Marko Rauhamaa <ma...@pacujo.net> wrote: >> I have wanted to use lists as keys, and there should be no reason to >> allow mutable tuples. It should be enough to say that the behavior of >> a dictionary is undefined if a key should mutate on the fly. > > Python defines dict-key-validity as being synonymous with hashability. > It's up to the class author to make sure the object's hash is useful.
>>> hash([]) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unhashable type: 'list' Annoying. > Behaviour being undefined works just fine [1] in C. It's not so > popular in Python. I don't think we want to have myriad new and > experienced programmers trying to figure out why square brackets in > dict keys are usually fine but occasionally not. But there's no way to enforce that with any of the myriad new classes. Ye blind guides, which strain at a gnat, and swallow a camel. But I say unto you, Swallow the gnat as well. Marko -- https://mail.python.org/mailman/listinfo/python-list