This code simply looks for a string in another string and returns the last postion of the occurance in the search string or -1 if its is not found.
I don't understand why my variable next_y is not updating considering that pos is an input into computation of next_y. My thought that is that if I update pos then next_y should also update. Instead pos gets updated and remains in the loop forever.
def find_last(x,y):
if x.find(y) == -1:
return -1
pos = x.find(y)
next_y = x.find(y, pos + 1)
while next_y != -1:
pos = pos + next_y
return pos
search = 'tom ran up but tom fell down'
target = 'tom'
print(find_last(search,target))
posthennext_yshould also update." You need to explicitly assign tonext_y, i.e.next_y = <insert something here>