Павлина обнови решението на 19.04.2012 02:45 (преди над 12 години)
+class BiDict():
+ def __init__(self, other_dict={}):
+ self.dict = dict(other_dict.items())
+
+ def __repr__(self):
+ return 'BiDict(' + str(self.dict) + ')'
+
+ def __getitem__(self, key):
+ return self.dict.__getitem__(key)
+
+ def __setitem__(self, key, what):
+ self.dict.__setitem__(key, what)
+
+ def keys(self):
+ return self.dict.keys()
+
+ def values(self):
+ return self.dict.values()
+
+ def items(self):
+ return self.dict.items()
+
+ def fromkeys(cls, value=0):
+ d = BiDict()
+ for x in len(cls):
+ d[key] = value
+ return d
+
+ def clear(self):
+ for i in range(len(self.dict)):
+ self.dict.popitem()
+
+ def pop(self, *args):
+ return self.dict.pop(*args)
+
+ def popitem(self):
+ self.dict.popitem()
+
+ def setdefault(self, key, default=0):
+ return self.dict.setdefault(key, default)
+
+ def __delitem__(self, key):
+ self.dict.__delitem__(key)
+
+ def __contains__(self, key):
+ return self.dict.__contains__(key)
+
+ def __eq__(self, other):
+ return self.dict.__eq__(other)
+
+ def __ne__(self, other):
+ return self.dict.__ne__(other)
+
+ def __iter__(self):
+ return self.dict.__iter__()
+
+ def get(self, key, default=0):
+ return self.dict.get(key, default)
+
+ def __len__(self):
+ return self.dict.__len__()
+
+ def update(self, other_dict):
+ self.dict.update(other_dict)
+ self.inverse()
+ self.inverse()
+
+ def inverse(self):
+ list = []
+ for x in range(len(self.dict)):
+ (x, y) = self.dict.popitem()
+ list.append((x, y))
+ for y in range(len(list)):
+ self.dict[list[y][1]] = list[y][0]