Planning a Python Course for Beginners

Marko Rauhamaa marko at pacujo.net
Wed Aug 9 06:38:58 EDT 2017


Chris Angelico <rosuav at gmail.com>:

> On Wed, Aug 9, 2017 at 7:51 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
>> Mutable objects can be used as keys into a dictionary.
>
> Only when the objects' mutability does not affect their values.

Up to equality. The objects can carry all kinds of mutable payload as
long as __hash__() and __eq__() don't change with it.

And Python doesn't enforce this in any way except for lists. That's
somewhat unfortunate since sometimes you really would like an immutable
(or rather, no-longer-mutable) list to act as a key.


Marko



More information about the Python-list mailing list