python-benedict/benedict/core/swap.py

9 lines
251 B
Python
Raw Permalink Normal View History

def swap(d, key1, key2):
if key1 == key2:
return
2022-07-15 21:54:34 +00:00
val1 = d[key1]
val1 = val1.copy() if isinstance(val1, dict) else val1
val2 = d[key2]
val2 = val2.copy() if isinstance(val2, dict) else val2
d[key1], d[key2] = val2, val1