【发布时间】:2021-02-27 17:40:23
【问题描述】:
所以,我有这个代码。
我想替换python字典中索引1处的特定现有键。
有人对此有想法吗?
from collections import OrderedDict
regDict= OrderedDict()
regDict[("glenn")] = 1
regDict[("elena")] = 2
print("dict",regDict)
打印:
dict OrderedDict([('glenn', 1), ('elena', 2)])
目标输出:
dict OrderedDict([('glenn', 1), ('new', 2)]) # replacing key in index 1
【问题讨论】:
-
这能回答你的问题吗? Change the name of a key in dictionary
标签: python dictionary ordereddict