dict_utils
add_key_in_dict_recursively(d, key, value, criteria=None)
Add a key in a dictionary recursively.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
d
|
Any
|
The dictionary to add the key to. |
required |
key
|
str
|
The key to add. |
required |
value
|
Any
|
The value to add. |
required |
criteria
|
Optional[Callable[[dict], bool]]
|
An optional function to determine if the key should be added. |
None
|
Source code in griptape/utils/dict_utils.py
dict_merge(dct, merge_dct, *, add_keys=True)
Recursive dict merge.
Inspired by :meth:dict.update()
, instead of
updating only top-level keys, dict_merge recurses down into dicts nested
to an arbitrary depth, updating keys. The merge_dct
is merged into
dct
.
This version will return a copy of the dictionary and leave the original arguments untouched.
The optional argument add_keys
, determines whether keys which are
present in merge_dict
but not dct
should be included in the
new dict.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dct
|
Optional[dict]
|
onto which the merge is executed |
required |
merge_dct
|
Optional[dict]
|
dct merged into dct |
required |
add_keys
|
bool
|
whether to add new keys |
True
|
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
updated dict |