我认为,这符合所有需要。 但是,一项法令不符合成员的要求,即确定现金,因此我们需要一个包裹。
class HashableDictWrapper(object):
def __init__(self, di):
self.di = di
self._hash_key = id("".join(["%s=%s" % (k, di[k]) for k in sorted(di.iterkeys())]))
def __hash__(self):
return self._hash_key
def __eq__(self, other):
return self.__hash__()==other.__hash__()
if __name__=="__main__":
t = ({ x :1}, { x :1}, { y :2})
s = set(map(HashableDictWrapper, t))
tuple(map(lambda a:a.di, s))
UPDATED:
I make some modifications to @monkut s answer:
t = ({ x :1}, { x :1}, { y :2})
p = map(lambda di:tuple((k,di[k]) for k in sorted(di.iterkeys())), t)
result = tuple(map(lambda x:dict(x), set(p)))