Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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)
Comment

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 :: add font to the label in window tkinter 
Python :: click button in selenium python 
Python :: how to create a database in python 
Python :: python shuffle list with seed 
Python :: como deixar todas as letras maiusculas no python 
Python :: Socket Programming Client Side 
Python :: python count distinct letters 
Python :: polyfit python 
Python :: pandas plot histogram 
Python :: python time in nanoseconds 
Python :: pandas replace column name from a dictionary 
Python :: python install bigquery 
Python :: sort list of dictionaries python 
Python :: python drop axis 
Python :: django phone number field 
Python :: pyqt5 qpushbutton disable 
Python :: solve system of linear equations numpy 
Python :: %matplotlib inline 
Python :: mad scipy 
Python :: add background image in django uploaded file 
Python :: is prime in python 
Python :: how to sort dictionary in python by value 
Python :: python get name of file 
Python :: python - show repeted values in a column 
Python :: python inline conditional 
Python :: scientific notation matplotlib python 
Python :: pandas read_csv nan as empty string 
Python :: ipython read audio file 
Python :: map function using lambda in python 
Python :: print () 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =