Planning a Python Course for Beginners

Chris Angelico rosuav at gmail.com
Wed Aug 9 06:59:18 EDT 2017


On Wed, Aug 9, 2017 at 8:38 PM, Marko Rauhamaa <marko at pacujo.net> wrote:
> 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.

Which means that its value won't change. That's what I said. Two
things will be equal regardless of that metadata.

> 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.

Then make a tuple out of it. Job done. You're trying to say that its
value won't now change.

ChrisA



More information about the Python-list mailing list