add a new key value pair to existing key value pair object in python -


python beginner here. have dictionary key , value object (dict) has key value pair. want add key value pair 'child' object.

given:

{"foo" :      {"bar" : "bars value"} } 

i want add:

{"foo" :      {"bar" : "bar value",       "baz" : "baz value"      } } 

this seems incredibly common can't seem find way it.

somedict = {"foo" :      {"bar" : "bars value"} }  somedict['foo']['baz'] = 'baz value' 

when python encounters somedict['foo']['baz'] first looks-up value of bare name somedict. finds dict. evaluates somedict['foo'] , finds dict. assigns dict new key 'baz' value `baz value'.


Comments