【问题标题】:Can I change the Key of a Dictionary with the value of another Dictionary that has the same Key in python?我可以用另一个在 python 中具有相同键的字典的值来更改字典的键吗?
【发布时间】:2021-04-09 18:40:45
【问题描述】:

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

我期望的输出如下:

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

提前致谢!

【问题讨论】:

标签: python dictionary


【解决方案1】:

您可以轻松地一步完成:

dictionary[new_key] = dictionary.pop(old_key)

【讨论】:

    猜你喜欢
    • 2018-12-05
    • 2011-10-12
    • 2021-10-07
    • 2017-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多