Say we have a list of dictionaries in Python:
A = [{'x': 1, 'y': 2, 'z': 3},{'x': 0, 'y': 10, 'z': 11}]
We pick out the ‘x’-values using map()
x = map((lambda i: i['x']), A)
and do something with them. Now, what is the cleanest way to update all the 'x'-values of A in a comparable way – ie., without using a for-loop?
In a single line?
Where, in this case, you’re incrementing the value of X. Although I’d suggest that this isn’t the prettiest way to do anything, nor the most readable. At least by doing the update method you’re not relying on a ‘hidden’ internal like setitem, and it’s a little more flexible in that you could be doing changes to more than one key at a time.