I have this function that works kind of like a tree traversal, but goes through a dictionary instead. Every key in the dict has two items in a list, so the structure is similar to a binary tree. I'm trying to find a specific key, while starting at a given key and when I find the key I want to stop my function and return the depth at which I'm at. I search through the dict find the key, but my recursive function doesn't stop at the return statement. My function:
def count(dict, key, depth):
if key is not None:
if key == 42:
return depth
return count(map, map[key][0], depth+1)
return count(map, map[key][1], depth+1)