Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Iterate through a nested dictionary

D = {'emp1': {'name': 'Bob', 'job': 'Mgr'},
     'emp2': {'name': 'Kim', 'job': 'Dev'},
     'emp3': {'name': 'Sam', 'job': 'Dev'}}

for id, info in D.items():
    print("
Employee ID:", id)
    for key in info:
        print(key + ':', info[key])

# Prints Employee ID: emp1
#        name: Bob
#        job: Mgr

#        Employee ID: emp2
#        name: Kim
#        job: Dev

#        Employee ID: emp3
#        name: Sam
#        job: Dev
Comment

looping nested dictionaries

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
Comment

PREVIOUS NEXT
Code Example
Python :: django orm 
Python :: import a module in python 
Python :: or in if statement python 
Python :: python typing union 
Python :: np diag 
Python :: how to connect mongodb database with python 
Python :: firestore search query flutter 
Python :: floor function in python 
Python :: python try except print error 
Python :: range 
Python :: flask page 
Python :: nested dictionary python 
Python :: concatenate lists 
Python :: create anaconda env 
Python :: when converting from dataframe to list delete nan values 
Python :: django cache framework 
Python :: infinity range or infinity looping 
Python :: Reset Index & Retain Old Index as Column in pandas 
Python :: icloud api python 
Python :: Simple Kivy pong game 
Python :: how to hack instagram account using python 
Python :: list all items in digital ocean spaces 
Python :: same line print python 
Python :: pandas month number to name 
Python :: loop in coding 1.2 
Python :: numpy create array with infinities 
Python :: gdal warp and glob through directory 
Python :: Finding best model using GridSearchCV 
Python :: train object detection model 
Python :: libraries used in ANN with Keras Sequential Model 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =