2020-02-03 17:25:54 +00:00
|
|
|
def move(d, key_src, key_dest, overwrite=True):
|
|
|
|
if key_dest == key_src:
|
|
|
|
return
|
|
|
|
if key_dest in d and not overwrite:
|
2020-09-07 17:25:34 +00:00
|
|
|
raise KeyError(
|
2022-02-18 00:02:02 +00:00
|
|
|
f"Invalid key: '{key_dest}', key already in target dict and 'overwrite' is disabled."
|
2021-10-12 12:27:35 +00:00
|
|
|
)
|
2020-02-03 17:25:54 +00:00
|
|
|
d[key_dest] = d.pop(key_src)
|