Home > front end >  how to find the par from the dict
how to find the par from the dict

Time:04-21

how to get only the par details from below nested dict. Requirement is to get only the par values from the below input. expected output to have only the parent values

 a = {
'a0': {
'sub_int': {
1: {
'name': 'xe-0/0/0:1',
'par': 'xe-0/0/0',
},
2: {
'name': 'xe-1/0/0:2',
'par': 'xe-1/0/0',
},
3: {
'name': 'xe-0/0/0:2',
'par': 'xe-0/0/0',
},
},
},
'a1': {
'sub_int': {
1: {
'name': 'xe-0/0/0:1',
'par': 'xe-0/0/0',
},
2: {
'name': 'xe-1/0/0:2',
'par': 'xe-1/0/0',
},
3: {
'name': 'xe-0/0/0:2',
'par': 'xe-0/0/0',
},
},
},
}

CodePudding user response:

Try this:

for my_dict in a:
    for my_dict_inner in a[my_dict]['sub_int']:
        print(a[my_dict]['sub_int'][my_dict_inner]['par'])
  • Related