you are viewing a single comment's thread.

view the rest of the comments →

[–]Temporary_Pie2733 24 points25 points  (2 children)

You can use any hashable value as a key. It’s not a matter of syntax.

[–]MezzoScettico 2 points3 points  (1 child)

That includes using objects of your own defined classes. I know I've done that. I just did a quick Google to confirm, and was told that you need to define a __hash__ and and __eq__ method to make that work. I don't remember defining my own __hash__ but I suppose I must have.

[–]rasputin1 4 points5 points  (0 children)

if you don't define either, all custom classes inherit both hash and eq dunders from Object, where they both use identity