-
Notifications
You must be signed in to change notification settings - Fork 0
/
dupe_key_dict.py
36 lines (29 loc) · 926 Bytes
/
dupe_key_dict.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
class DupeKeyDict():
def __init__(self, d=None):
if d is not None:
self._keys = list(d.keys())
self._values = list(d.values())
else:
self._keys = []
self._values = []
def __setitem__(self, key, value):
self._keys.append(key)
self._values.append(value)
def __delitem__(self, key):
idx = self._keys.index(key)
self._keys.pop(idx)
self._values.pop(idx)
def __iter__(self):
return iter(self._keys)
def update(self, d):
self._keys.extend(d.keys())
self._values.extend(d.values())
def keys(self):
return self._keys
def values(self):
return self._values
def __repr__(self):
res = []
for i in range(len(self._keys)):
res.append("'{0}': {1}".format(self._keys[i], self._values[i]))
return '{' + ', '.join(res) + '}'