On Thu, Nov 26, 2015 at 5:52 PM, Marko Rauhamaa <ma...@pacujo.net> wrote: > Steven D'Aprano <st...@pearwood.info>: > >> Making tuples mutable would break their use as dictionary keys, which is a >> *critical* use. > > No, it wouldn't. Any object that provides __hash__() and __eq__() can be > used as a key. > > Nothing prevents using mutable objects as keys in Python. > >
Sure, you _can_. But if the key's hash changes between dict insertion and retrieval, all manner of invariants will break, and likewise if two equal objects have different hashes. From which you can deduce logically that any object used as a key must remain (not) equal to everything that it was (not) equal to from that time until it is looked up... which basically means its value mustn't change. It must be immutable. ChrisA -- https://mail.python.org/mailman/listinfo/python-list