3 ms·
> any immutable object as a key Any hashable object, technically. Especially with custom objects, the two (immutability and hashability) don’t necessarily have
by mplanchard 7y ago
> any immutable object as a key
Any hashable object, technically. Especially with custom objects, the two (immutability and hashability) don’t necessarily have to overlap, although it’s often a bad idea to have hashable, mutable objects
- abhishekjha 7y agoMutable objects can't be hashed right?
- detaro 7y agoAs the comment you responded to says: An object can be mutable and hashable. E.g. any custom class by default has mutable and hashable instances.
- abhishekjha 7y agoHow can you get both mutable and hashable instances at the same time?
- detaro 7y agothe only requirement on a hashable instance is that it implements a proper __hash__ function. The default implementation in CPython returns the address of the memory the object is stored at, so all instances are considered unique, values play no role at all.