Is there a way to rename a dictionary key, without reassigning its value to a new name and removing the old name key; and without iterating through dict key/value? I
A few people before me mentioned the .pop trick to delete and create a key in a one-liner.
.pop
I personally find the more explicit implementation more readable:
d = {'a': 1, 'b': 2} v = d['b'] del d['b'] d['c'] = v
The code above returns {'a': 1, 'c': 2}
{'a': 1, 'c': 2}