Илиян обнови решението на 19.04.2012 10:37 (преди над 12 години)
+class BiDict(dict):
+
+ def __init__(self, *args, **kwargs):
+ super(BiDict, self).__init__()
+ for element in args:
+ for key, value in element.items():
+ hash(key)
+ hash(value)
+ self[key] = value
+ for key, value in kwargs.items():
+ hash(key)
+ hash(value)
+ self[key] = value
+
+ def __setitem__(self, argument_key, argument_value):
+ hash(argument_value)
+ hash(argument_key)
+ equal_values = False
+ for key_in_dict, value_in_dict in self.items():
+ if self[key_in_dict] == argument_value:
+ equal_values = True
+ key_for_delete = key_in_dict
+ if equal_values == True:
+ del self[key_for_delete]
+ super().__setitem__(argument_key, argument_value)
+
+ def update(self, update_of_dict):
+ for key, value in update_of_dict.items():
+ hash(key)
+ hash(value)
+ self[key] = value
+
+ def inverse(self):
+ stack = []
+ copy_of_our_dict = {}
+ for key, value in self.items():
+ copy_of_our_dict = {value: key}
+ stack.append(copy_of_our_dict)
+ self.clear()
+ for inversed_dict in stack:
+ self.update(inversed_dict)