qspec logo qspec logo

A physics toolbox for laser spectroscopy.

Static Badge Static Badge Static Badge

Static Badge Static Badge

© 2026 Patrick Müller. All rights reserved.

qspec. add_nested_key  (  a ,  key_list ,  val  )[source]

Assign a value to a nested key of a dictionary, creating the intermediate dictionaries if necessary.

Parameters:
adict

The target dictionary.

key_listlist

A list of nested keys of a.

valarray_like

The value that is assigned to the last key in key_list.

Returns:
adict

The dictionary a with val assigned to the last key in key_list.

Raises:
TypeError

If an intermediate value is not a dictionary.