I have a simple code that finds paths using a graph stored in a dictionary. The code is exactly:
def find_path(dct, init, depth, path=[]):
if depth == 0:
return path
next_ = dct[init]
depth-=1
find_path(dct, next_, depth)
If I print the path right before return path
it prints to screen the correct path (after an initial depth of 5
). However, the value returned is None
. I don't know what's going on!
Why would the value of path
right above the return
is correct, yet the returned path is not what I want?