7.2.8.12. selector¶
- selector(keys, dictionary, copy=False, output_type='dict', allow_miss=False)[source]¶
Selects the chosen dictionary keys from the given dictionary.
- Parameters:
dictionary (dict) – A dictionary.
copy (bool) – If True the output contains deep-copies of the values.
output_type –
Type of function output:
’list’: a list with all values listed in keys.
’dict’: a dictionary with any outputs listed in keys.
- ’values’: if output length == 1 return a single value otherwise a
tuple with all values listed in keys.
- type output_type:
str, optional
allow_miss (bool) – If True it does not raise when some key is missing in the dictionary.
- Returns:
A dictionary with chosen dictionary keys if present in the sequence of dictionaries. These are combined with
combine_dicts()
.- Return type:
Example:
>>> import schedula as sh >>> fun = sh.partial(selector, ['a', 'b']) >>> sorted(fun({'a': 1, 'b': 2, 'c': 3}).items()) [('a', 1), ('b', 2)]