self.inverse = {}
for key, value in self.items():
    self.inverse.setdefault(value, []).append(key)

def __setitem__(self, key, value):
    super(bidict, self).__setitem__(key, value)
self.inverse.setdefault(value, []).append(key)

def __delitem__(self, key):
    self.inverse.setdefault(self[key], []).remove(key)
if self[key] in self.inverse and not self.inverse[self[key]]:
    del self.inverse[self[key]]
super(bidict, self).__delitem__(key)
Эффективная двунаправленная хеш-таблица в Python?