Dict manip
load_yaml(input_yaml)
¶
Load the yaml file
Source code in automation/utils/dict_manip.py
8 9 10 11 12 |
|
sort_dict(my_dict, my_list)
¶
Sort dict by list of keys. Return OrderedDict
Source code in automation/utils/dict_manip.py
15 16 17 18 19 20 21 |
|
flatten_embedded(input_dict)
¶
Check vals in input. If dict, make embedded values new keys in output dict
Novel keys in output dict are {'key_embedded-key': 'embedded_value'}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_dict |
dict
|
any dict |
required |
Returns:
Type | Description |
---|---|
dict
|
output_dict (dict) |
Source code in automation/utils/dict_manip.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
filter_dict_by_key(dict_content, key_filter='Type', key_options=None)
¶
Filter an embedded dict by if values of key_filter in listed key_options
Example
my_dict = {"a": {"b": 1}, "c": {"b": 2}, "d": {"b": 3}} filter_dict_by_key(dict_content=my_dict,key_filter="b",key_options=[1,2])
{'a': {'b': 1}, 'c': {'b': 2}}
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dict_content |
dict
|
Input dict |
required |
key_filter |
str
|
Optional specification of key. Default "Type" |
'Type'
|
key_options |
set
|
Set of items that, when retyped to list must match value[list_filter]. |
None
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
filtered dict |
Source code in automation/utils/dict_manip.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|