app/soc/logic/dicts.py
changeset 486 ec6b50f48d3b
parent 484 6364f8b0656b
child 499 d22e4fe8e64b
equal deleted inserted replaced
485:2865922ea06a 486:ec6b50f48d3b
    85       value = None
    85       value = None
    86     key = keys[i]
    86     key = keys[i]
    87     result[key] = value
    87     result[key] = value
    88 
    88 
    89   return result
    89   return result
       
    90 
       
    91 def rename(target, keys):
       
    92   """Returns a dict containing only the key/value pairs from keys
       
    93 
       
    94   The keys from target will be looked up in keys, and the corresponding
       
    95   value from keys will be used instead. If a key is not found, it is skipped.
       
    96 
       
    97   Args:
       
    98     target: the dictionary to filter
       
    99     keys: the fields to filter
       
   100   """
       
   101 
       
   102   result = {}
       
   103 
       
   104   for key, value in target.iteritems():
       
   105     if key in keys:
       
   106       new_key = keys[key]
       
   107       result[new_key] = value
       
   108 
       
   109   return result