我可以使用另一个在python中具有相同键的字典的值来更改字典的键吗?

时间:2021-04-09 18:40:45

标签: python dictionary

简而言之,我想用另一个与第一个字典具有相同键的字典的值替换字典中的键。

enter image description here

我期望的输出如下:

{'Sneakers-Viewed Product-(not set)' : 2}

提前致谢!

1 个答案:

答案 0 :(得分:0)

您只需一步即可轻松完成此操作:

dictionary[new_key] = dictionary.pop(old_key)