3 ms·
It’s been a while, but I’m pretty sure the reason why a dictionary can’t have a dictionary as it’s key is because the dictionary class doesn’t implement the __h
by fiddlerwoaroof 8y ago
It’s been a while, but I’m pretty sure the reason why a dictionary can’t have a dictionary as it’s key is because the dictionary class doesn’t implement the __hash__ method that would compute the hashcode.
- np_tedious 8y agoThis is definitely the proximate reason. The reason for that choice is because the object is mutable.
- fiddlerwoaroof 8y agoSure, but as others have mentioned, you can make your own choice by subclassing dict and defining your own hash function, as long as that function is defined in a way that follows the appropriate rules.