Python get nested dictionary keys | Example code

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:

Python get nested dictionary keys

Do comment if you have any doubts and suggestions on this Python dictionary topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.