Answers for "python iterate over multidimensional dictionary"

1

python iterate over multidimensional dictionary

d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}

for i in d.keys():
    print(i)
    for j in d[i].keys():
        print(j)
Posted by: Guest on July-13-2021
-1

iterate through nested dictionary python

d = {'dict1': {'foo': 1, 'bar': 2}, 'dict2': {'baz': 3, 'quux': 4}}

    for k1,v1 in d.iteritems(): # the basic way
        temp = ""   
        temp+=k1
        for k2,v2 in v1.iteritems():
           temp = temp+" "+str(k2)+" "+str(v2)
        print temp
Posted by: Guest on January-14-2021

Code answers related to "python iterate over multidimensional dictionary"

Python Answers by Framework

Browse Popular Code Answers by Language