Answers for "python change key of dict"

7

modify dict key name python

a_dict[new_key] = a_dict.pop(old_key)
Posted by: Guest on August-03-2020
-2

python change dict key value

# an example of creating a new dict key from an existing one, then deleting the old key
d = {"cow": "animal", "rose": "flower"}
d["horse"] = d["cow"]
del d["cow"]
Posted by: Guest on April-20-2022

Python Answers by Framework

Browse Popular Code Answers by Language