defrecursive_items(dictionary):for key, value in dictionary.items():iftype(value)isdict:yieldfrom recursive_items(value)else:yield(key, value)
a ={'a':{1:{1:2,3:4},2:{5:6}}}for key, value in recursive_items(a):print(key, value)
how to print a value of a key in nested dictionary python
D ={'emp1':{'name':'Bob','job':'Mgr'},'emp2':{'name':'Kim','job':'Dev'},'emp3':{'name':'Sam','job':'Dev'}}print(D['emp1']['name'])# Prints Bobprint(D['emp2']['job'])# Prints Dev
Accessing elements from a Python Nested Dictionary
# welcome to softhunt.net# Creating a Dictionary
Dictionary ={0:'Softhunt',1:'.net',2:{'i':'By','ii':'Ranjeet','iii':'Andani'}}print('Dictionary', Dictionary)# Accessing element using keyprint(Dictionary[0])print(Dictionary[2]['i'])print(Dictionary[2]['ii'])