Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python count nested keys

# Example usage:
# If you want to count keys in a nested dictionary, you can use this
# recursive function:

def count_keys(d):
    """
    recursively count keys in a nested dictionary
    """
    keys = 0
    if type(d) == dict:
        for key in d.keys():
            if isinstance(d[key], dict):
                keys += 1
                k = count_keys(d[key])
                keys += k
            else:
                keys += 1
    return keys
Comment

PREVIOUS NEXT
Code Example
Python :: xgboost feature importance 
Python :: isinstance numpy array 
Python :: how to get variable from setings django 
Python :: insert image to jupyter notebook 
Python :: List comprehension - list files with extension in a directory 
Python :: python count repeated elements in a list 
Python :: pandas find top 10 values in column 
Python :: yesterday in python 
Python :: pandas multiple string contains 
Python :: types of all columns pandas 
Python :: pandas shift column 
Python :: interpoltaion search formula python 
Python :: python day from date 
Python :: how to find and replace all the punctuation in python strings 
Python :: trigonometry in python 
Python :: matplotlib wrap title 
Python :: update python 3.10 ubuntu 
Python :: install auto-py-to-exe 
Python :: how to get data from json web api in python 
Python :: python image to pdf 
Python :: how to add input box in tkinter 
Python :: run flask application in development mode stack overflow 
Python :: remove scientific notation python matplotlib 
Python :: get file extension python 
Python :: discord identity python html avatar 
Python :: get ip from request django 
Python :: python drop rows with two conditions 
Python :: python iterate object 
Python :: check if regex matches python 
Python :: pip install contractions 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =