differentiate between two values with same key in a nested dictionary [closed]

ⅰ亾dé卋堺 提交于 2021-02-05 12:34:55

问题


I have a nested dictionary in Python with the following structure:

d= {
 'name': 'test',
 'IBM': 146.48,
 'MSFT': 44.11,
 'CSCO': 25.54,
 'micro': {'name': 'test', 'age': 1}
}

In my code I want to change the value of the first key name. When I do:

for k, v in d.items():
    d[k] = newvalue

All the values of keys = name change to my new value. But I want to only change the value of the first key name.

How to fix this?

来源:https://stackoverflow.com/questions/65994092/differentiate-between-two-values-with-same-key-in-a-nested-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!