Just iterate every inner dictionary one by one and get nested dictionary keys in Python.
Example get nested dictionary keys in Python
Simple example code using for loop to iterate a given dictionary. In this method, you will get all keys of the inner dictionary.
Employee = {
'emp1': {
'name': 'John',
'age': '29',
'Designation': 'Programmer'
},
'emp2': {
'name': 'Steve',
'age': '45',
'Designation': 'HR'
}
}
for k, v in Employee.items():
for k1, v1 in v.items():
print(k1)
Output:
Do comment if you have any doubts and suggestions on this Python dictionary topic.
Note: IDE: PyCharm 2021.3.3 (Community Edition)
Windows 10
Python 3.10.1
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.