Like for the list.sort() method, to remind you that this function operate by side effect, maybe it's better if it doesn't return the modified nested dict: def setNested(nest, path, val): nest2 = nest for key in path[:-1]: nest2 = nest2[key] nest2[path[-1]] = val Bye, bearophile