I have a nested dictionary and I want to update the value of an item based on its key value. For example, I have the following dictionary and I want to set the value of every occurrence of an item with key=='p' to be 1.
my_dict = {'p': 0, 'nested_dict': {'p': 0, 'a': 2}}
For a regular dictionary (non-nested) the update method provides a simple one-liner solution:
my_dict.update((x, 1) for x, y in my_dict.items() if x=='p')
I'm looking for a similar solution for the case of nested dictionary