Edit the values in a list of dictionaries?

I did not do any timings, but you probably can’t get much better than

for d in my_dicts:
    d.update((k, "value3") for k, v in d.iteritems() if v == "value2")

Update for Python3

for d in my_dicts:
    d.update((k, "value3") for k, v in d.items() if v == "value2")

Leave a Comment