Lookup table for unhashable in Python

后端 未结 4 1663
粉色の甜心
粉色の甜心 2021-01-12 19:45

I need to create a mapping from objects of my own custom class (derived from dict) to objects of another custom class. As I see it there are two ways of doing this:

4条回答
  •  既然无缘
    2021-01-12 20:15

    The following should work if you're not storing any additional unhashable objects in your custom class:

    def __hash__(self):
        return hash(self.items())
    

提交回复
热议问题