python: Convert a for loop into a recursion function

后端 未结 3 1776
死守一世寂寞
死守一世寂寞 2021-01-14 06:46

First of all, I\'m still a newb to python so please take it easy on me.

I\'ve done my research and I have a basic understanding of how to write a recursive function

3条回答
  •  攒了一身酷
    2021-01-14 07:16

    Here is an example approach to recursively go through a dictionary, assuming that each child is also a dictionary:

    def compute(my_dict):
        if 'children' in my_dict:
            print my_dict['children']
            for child in my_dict['children']:
                compute(child)
    

提交回复
热议问题