Skip to main content
Home
badllama.com
  • Search
  • Log In

Python Recursion

Recurse all dictionary values

cpeters's picture

Tue, 04/05/2016 - 13:13 by cpeters

#recursively create a list of all dictionary values
def get_list(d,l=[]):
    for key in d:
        if isinstance(d[key], dict):
            l = get_list(d[key], l)
        else:
            l.append(key + " - {}".format(d[key],str))
    return l
Tags: 
Python Recursion
  • Read more about Recurse all dictionary values
Powered by Backdrop CMS