Replacing values in a Python list/dictionary?
DATA = {"records": [{"key1": "AAA", "key2": "BBB", "key3": "CCC", "key4": "AAA"}]}
for name, datalist in DATA.iteritems(): # Or items() in Python 3.x
for datadict in datalist:
for key, value in datadict.items():
if value == "AAA":
datadict[key] = "XXX"
print (DATA)
# Prints {'records': [{'key3': 'CCC', 'key2': 'BBB', 'key1': 'XXX', 'key4': 'XXX'}]}
dic = root['records'][0]
for i, j in dic.items(): # use iteritems in py2k
if j == 'AAA':
dic[i] = 'xxx'