Krishn Krishn - 1 month ago 5x
Python Question

Get all keys of a nested dictionary

I have the below code which currently just prints the values of the initial dictionary. However I would like to iterate through every key of the nested dictionary to initially just print the names. Please see my code below

Liverpool = {
'Keepers':{'Loris Karius':1,'Simon Mignolet':2,'Alex Manninger':3},
'Defenders':{'Nathaniel Clyne':3,'Dejan Lovren':4,'Joel Matip':5,'Alberto Moreno':6,'Ragnar Klavan':7,'Joe Gomez':8,'Mamadou Sakho':9}


for k,v in Liverpool.items():
if k =='Defenders':


Here is code that would print all team members:

for k, v in Liverpool.items():
    for k1, v1 in v.items():

So you just iterate every inner dictionary one by one and print values

UPDATE: printed numbers not names at first