Project

General

Profile

« Previous | Next » 

Revision 4100

util.py: dict_subset(): Fall back to using dict when OrderedDict is not available, in order to support making the maps on nimoy

View differences:

lib/util.py
1 1
# Useful functions and classes
2 2

  
3 3
import collections
4
from ordereddict import OrderedDict
5 4

  
6 5
import dicts
7 6
import objects
......
187 186
def rename_key(dict_, orig, new): dict_[new] = dict_.pop(orig)
188 187

  
189 188
def dict_subset(dict_, keys):
190
    subset = OrderedDict()
189
    try: from ordereddict import OrderedDict
190
    except ImportError: subset = dict()
191
    else: subset = OrderedDict()
191 192
    for key in keys:
192 193
        try: subset[key] = dict_[key]
193 194
        except KeyError: pass

Also available in: Unified diff