root/lib/dicts.py @ 1878
1 |
# Dictionaries
|
---|---|
2 |
|
3 |
def id_dict(objects=[]): |
4 |
'''Makes a dict of objects by id() value'''
|
5 |
return dict(((id(v), v) for v in objects)) |
6 |
|
7 |
class MergeDict: |
8 |
'''A dict that checks each of several dicts'''
|
9 |
def __init__(self, *dicts): self.dicts = dicts |
10 |
|
11 |
def __getitem__(self, key): |
12 |
for dict_ in self.dicts: |
13 |
try: return dict_[key] |
14 |
except KeyError: pass |
15 |
raise # reraise last KeyError |