aim2dat.utils.dict_tools

Module implementing several functions to handle nested python dictionaries.

Module Contents

Functions

dict_create_tree(dictionary, parameter_tree)

Create a nested dictionary.

dict_merge(a, b[, path])

Merge two dictionaries.

dict_retrieve_parameter(dictionary, parameter_tree)

Retrieve value from nested dictionary.

dict_set_parameter(dictionary, parameter_tree, value)

Set parameter in a nested dictionary.

aim2dat.utils.dict_tools.dict_create_tree(dictionary, parameter_tree)[source]

Create a nested dictionary.

Parameters:
  • dictionary (dict) – Input dictionary.

  • parameter_tree (list) – List of dictionary key words.

aim2dat.utils.dict_tools.dict_merge(a, b, path=None)[source]

Merge two dictionaries.

Parameters:
  • a (dict) – Dictionary to be merged into.

  • b (dict) – Dictionary to be merged.

  • path (str or None (optional)) – Parameter path of dictionary a.

aim2dat.utils.dict_tools.dict_retrieve_parameter(dictionary, parameter_tree)[source]

Retrieve value from nested dictionary.

Parameters:
  • dictionary (dict) – Input dictionary.

  • parameter_tree (list) – List of dictionary key words.

Returns:

value – The value of the parameter or None if the key word cound not be found.

aim2dat.utils.dict_tools.dict_set_parameter(dictionary, parameter_tree, value)[source]

Set parameter in a nested dictionary.

Parameters:
  • dictionary (dict) – Input dictionary.

  • parameter_tree (list) – List of dictionary key words.

  • value (str, float or int) – Value of the parameter.

Returns:

dictionary (dict) – Output dictionary.