darbia.utils.mappings#

Assorted utility functions.

Module Contents#

Functions#

dict_compare(→ tuple[list[Any], list[Any], dict[Any, ...)

Compare two different dictionaries.

get_nested_dict_value(→ T)

Parse nested values from dictionaries.

keychain(→ dict)

Create a dict of chains of keys from sequential dicts.

Attributes#

T

darbia.utils.mappings.T[source]#
darbia.utils.mappings.dict_compare(old_dict: dict[Any, Any], new_dict: dict[Any, Any]) tuple[list[Any], list[Any], dict[Any, Any], list[Any]][source]#

Compare two different dictionaries.

Parameters:
  • old_dict (dict[Any, Any]) – The old dictionary

  • new_dict (dict[Any, Any]) – The new dictionary

Returns:

Comparison results

Return type:

(list[Any], list[Any], dict[Any, Any], list[Any])

Examples

>>> dict_compare(old_dict=dict(), new_dict=dict())
([], [], {}, [])

Notes

https://stackoverflow.com/a/18860653

darbia.utils.mappings.get_nested_dict_value(dct: dict, keypath: str, default: T = None, separator: str = '.') T[source]#

Parse nested values from dictionaries.

Parameters:
  • dct – The dictionary to search

  • keypath – The path of keys to check through

  • default – The default value to return if the value is not found

  • separator – The character used to split the keypath

Return type:

The value at the keypath or the default value

Examples

>>> get_nested_dict_value({"key": {"path": "value"}}, "key.path")
'value'
darbia.utils.mappings.keychain(dicts: list[dict]) dict[source]#

Create a dict of chains of keys from sequential dicts.

Parameters:

dicts – The list of dictionaries to chain

Return type:

A dictionary of lists of all chains

Notes

https://discord.com/channels/267624335836053506/587375768556797982/1044549320948584528