Home > OS >  How do I append values to a nested dictionary in Python?
How do I append values to a nested dictionary in Python?

Time:01-29

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. I want this value to be appended to the dictionary, mydict, to the 'Temp Count' key. The above is what I have.

Is there a way I can do this?

Thank you

CodePudding user response:

Not sure what you want, but probably

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

CodePudding user response:

perhaps

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

  •  Tags:  
  • Related