Project

General

Profile

« Previous | Next » 

Revision 467

util.py: Fixed dict_subset() to work correctly when a key does not exist

View differences:

lib/util.py
16 16

  
17 17
def rename_key(dict_, orig, new): dict_[new] = dict_.pop(orig)
18 18

  
19
def dict_subset(dict_, keys): dict([(key, dict_[key]) for key in keys])
19
def dict_subset(dict_, keys):
20
    subset = dict()
21
    for key in keys:
22
        try: subset[key] = dict_[key]
23
        except KeyError: pass
24
    return subset

Also available in: Unified diff