Revision 3157
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/util.py | ||
---|---|---|
1 | 1 |
# Useful functions and classes |
2 | 2 |
|
3 | 3 |
import collections |
4 |
from ordereddict import OrderedDict |
|
4 | 5 |
|
5 | 6 |
import dicts |
6 | 7 |
import objects |
... | ... | |
179 | 180 |
def rename_key(dict_, orig, new): dict_[new] = dict_.pop(orig) |
180 | 181 |
|
181 | 182 |
def dict_subset(dict_, keys): |
182 |
subset = dict()
|
|
183 |
subset = OrderedDict()
|
|
183 | 184 |
for key in keys: |
184 | 185 |
try: subset[key] = dict_[key] |
185 | 186 |
except KeyError: pass |
Also available in: Unified diff
util.py: dict_subset(): Use OrderedDict so that order of keys in input dict (if ordered) will be preserved