in Programming recategorized by
98 views
0 votes
0 votes
Consider the following Python code:

def countchildren(l, i):
    Some code
    Given lists
    if i > 2:
        return 1
    ans = 1
    for i in l.keys():
        ans = ans + countchildren(l,i)
    return ans
Example usage
l = dict()
l[1] = [2, 3]
l[2] = [3, 4, 5]
l[3] = [6, 7, 8]
result = countchildren(l,1)
print(result)
in Programming recategorized by
98 views

Please log in or register to answer this question.