idea on how to get/set nested python dictionary values

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Tue Aug 15 19:12:11 EDT 2006


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




More information about the Python-list mailing list