简体   繁体   English

如何将 append 值添加到 Python 中的嵌套字典中?

[英]How do I append values to a nested dictionary in Python?

def writeTempsData(Temperature):

    mydict = {
           '1':   {'Location': 'Adelaide','Temp Count':''},
           '2':   {'Location': 'Perth','Temp Count':''},
           '3':   {'Location': 'Melbourne','Temp Count':''},
           '4':   {'Location': 'Canberra','Temp Count':''},
           '5':   {'Location': 'Sydney','Temp Count':''},
           '6':   {'Location': 'Brisbane','Temp Count':''},
           '7':   {'Location': 'Darwin','Temp Count':''}
    }


    for row in mydict:
        if row['Location'] == 'Adelaide':
            print(daysOver('weatherAUS-1 - Practical 3.csv',value,Temperature))

So, the daysOver function is something that I am using to get a value.所以,daysOver function 是我用来获取价值的东西。 I want this value to be appended to the dictionary, mydict, to the 'Temp Count' key.我希望将此值附加到字典 mydict 的“临时计数”键中。 The above is what I have.以上是我所拥有的。

Is there a way I can do this?有没有办法我可以做到这一点?

Thank you谢谢

Not sure what you want, but probably不确定你想要什么,但可能

row['Temp Count'] = daysOver('weatherAUS-1 - Practical 3.csv',value,Temperature)

perhaps也许

for key in mydict.keys:
   for item in mydict[key]:
        item['Temp count'][0] = temperature_value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM