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
代码返回[]
,但我希望看到[5]
,所以我认为问题在于它n
意外增加然后进行letter2
更改。为什么此代码n
在完成for
循环(在位置 1)之前递增(在位置 2)?