How is this recursion properly working when it is iterated through [on hold]
- by Rakso Zrobin
Here is my code right now:
hasht= {"A":["B", "D", "E"],
"B":["C"],
"C":["D", "E"],
"D":["C", "E"],
"E":["B"]}
paths=[]
def recusive(start, finish, started=true):
if start==finish and !started:
return start
else:
for i in hasht[start]:
path= start+ recusive(i,finish,false)
paths.append(path)
print (recusive("C","C",1))
print paths
# [CDC, CDEBC, CEBC]
I am trying to generate a table like the one on the bottom, but am running into the problem of the string and the array not being able to concatenate. When I just return however, it returns CDC and works, however, exiting the function as return is meant to do.
I am wondering how I can improve my code here to (1) make it work,
(2) why my logic was faulty. For example, I understand that it generates say [DC], but I am confused as to how to go around that. perhaps index the value returned?