``` a_string = 'abc' destination = [2, 3] edges = { (1, 'a') : [2, 3], (2, 'a') : [2], (3, 'b') : [4, 3], (4, 'c') : [5] } def make(a_string, destination, edges): n = 0 while n + 1 < len(a_string): letter = a_string[n] letter2 = a_string[n + 1] for d in destination: # (1) if (d, letter2) in edges: for state in edges[(d, letter2)]: destionation.append(state) destination.remove(d) n += 1 # (2) return destination ``` The code return [], but I expect to see [5], so I think the problem is that it increment n unexpectedly then make letter2 change. Why does this code increment n (at position 2) before completing the for loop (at position 1)?
I don't know python, but I put it in a code block for you to make it easier to read and so it would highlight. :)
ok, thank you.
Can you describe the function a bit more?
Are you sure that you're getting what you expect as destination when the function is called? You have no test, it's just a blind iteration. Just for debugging, why not print out string, destination and edges to make sure of your data?
OK, now I think it is clearer
Join our real-time social learning platform and learn together with your friends!