Mithel
Mithel

Reputation: 185

How to retrieve the value of a multi nested dictionary

Data={
    0:{
       'country_two': "3",
       'country_one': "5",
       'med_dict':{
          0: {
              'endDate': "732",
              'endTime': "89",
             }
       },
     },
    1: {
        'country_four': "2",
        'country_three': "90",
        'med_dict': {
          0: {
              'endDate': "245",
              'endTime': "222",
              }
        },

    }
}

I want to retrieve the maximum value for med_dict['endDate'] in this above dictionary. How to retrieve data in such dictionary for specific key like 'med_dict'?

Upvotes: 1

Views: 61

Answers (2)

Hamilton Hardy
Hamilton Hardy

Reputation: 97

maxVal = Data.get(0).get('med_dict').get(0).get('endDate')

I would simplify that dictionary. Way too overly complicated.

Upvotes: 1

Daniel Hao
Daniel Hao

Reputation: 4981

Try to start with something like this: (skip last step on purpose, it's for you to get it, which is super straightforward) ;-)


for k in Data:
    print(Data[k]['med_dict'][0]['endDate'])

Upvotes: 1

Related Questions