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

PREVIOUS NEXT
Code Example
Python :: pandas normalize columns 
Python :: python dataclass 
Python :: Python RegEx Findall – re.findall() 
Python :: python return using if 
Python :: throughput in os 
Python :: spacy tokineze stream 
Python :: python youtube downloader 
Python :: check if number in range python 
Python :: append to list py 
Python :: pandas -inf and inf to 0 
Python :: install local package python 
Python :: python tkinter grid 
Python :: flatten list python 
Python :: FIND MISSING NUMBER IN AN ARRAY IN PYTHON 
Python :: python snake case to camel case 
Python :: cv2 get framerete video 
Python :: python append variable to list 
Python :: python color print 
Python :: target ordinary encodiing) 
Python :: how to bold in colorama 
Python :: next() python 
Python :: how to convert binary to integer in python 
Python :: how to make variable global in python 
Python :: python tkinter listbox detect selection change 
Python :: remove prefix in python 3.6 
Python :: increment python 
Python :: tuple comprehension python 
Python :: np.where 
Python :: python makedir 
Python :: coloring text in python 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =