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

PREVIOUS NEXT
Code Example
Python :: django password field 
Python :: google-api-python-client python 3 
Python :: how to convert text to speech using pthon 
Python :: handwriting python 
Python :: pandas count values by column 
Python :: save turtle programming python 
Python :: find max in a dataframe 
Python :: index from multiindex pandas 
Python :: search in dict python 
Python :: what is *args and **kwargs in django 
Python :: how to read files in python with 
Python :: python array 
Python :: how to change index in dataframe python 
Python :: how to print a variable in python 
Python :: import yaml python3 
Python :: Python program to print negative numbers in a list 
Python :: how to write variables in python 
Python :: import all csv python 
Python :: Handling categorical feature 
Python :: python custom exception 
Python :: pi in python 
Python :: import tsv as dataframe python 
Python :: square root python 3 
Python :: plot title overlapping yaxis python 
Python :: insert row at given position in pandas dataframe 
Python :: end in print python 
Python :: flask blueprint 
Python :: python string to list of int 
Python :: bs4 innerhtml 
Python :: get all files in pc python 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =