Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to get key value in nested dictionary python

def recursive_items(dictionary):
    for key, value in dictionary.items():
        if type(value) is dict:
            yield from recursive_items(value)
        else:
            yield (key, value)

a = {'a': {1: {1: 2, 3: 4}, 2: {5: 6}}}

for key, value in recursive_items(a):
    print(key, value)
Comment

python get nested dictionary keys

example_dict.get('key1', {}).get('key2')
Comment

Nested dictionary Python

IDs = ['emp1','emp2','emp3']

EmpInfo = [{'name': 'Bob', 'job': 'Mgr'},
           {'name': 'Kim', 'job': 'Dev'},
           {'name': 'Sam', 'job': 'Dev'}]

D = dict(zip(IDs, EmpInfo))

print(D)
# Prints {'emp1': {'name': 'Bob', 'job': 'Mgr'},
#         'emp2': {'name': 'Kim', 'job': 'Dev'},
#         'emp3': {'name': 'Sam', 'job': 'Dev'}}
Comment

Accessing elements from a Python Nested Dictionary

# welcome to softhunt.net
# Creating a Dictionary
Dictionary = {0: 'Softhunt', 1: '.net',
		2:{'i' : 'By', 'ii' : 'Ranjeet', 'iii' : 'Andani'}}
print('Dictionary', Dictionary)

# Accessing element using key
print(Dictionary[0])
print(Dictionary[2]['i'])
print(Dictionary[2]['ii'])
Comment

Nested dictionary Python

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

print nested dictionary values in python

for account in bank_dictionary:
    print("
 ACCOUNT: ", account)
    for subaccount in bank_dictionary[account]:
        print("
 Subaccount: ", subaccount)
Comment

PREVIOUS NEXT
Code Example
Python :: change data type python 
Python :: python verify if string is a integer 
Python :: python print date, time and timezone 
Python :: convex hull python 
Python :: Python NumPy ndarray flatten Function Example 
Python :: register template tag django 
Python :: lambda and function in python 
Python :: how to plot kmeans centroids 
Python :: datetime decreasing date python 
Python :: python random select no replace 
Python :: uses specific version python venv 
Python :: python count 
Python :: python read file xlsx and return a list 
Python :: create python executable 
Python :: write image out opencv 
Python :: how to count repeated words in python 
Python :: how to add createsuper user in django 
Python :: box plot python 
Python :: activate python virtual environment 
Python :: how to count the lines of code using open in python 
Python :: delimiter pandas 
Python :: PY | websocket - client 
Python :: how to create pyw file 
Python :: python how to check in a list 
Python :: pyton recognize any datetime format 
Python :: python read input 
Python :: type python 
Python :: keras model save 
Python :: pandas: split string, and count values? 
Python :: python convert bytes to string 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =