I am trying to print out the positions of a given substring inside of a string, but on line 18 I keep getting the error
Traceback (most recent call last):
File "prog.py", line 18, in <module>
TypeError: 'int' object has no attribute '__getitem__'
I have no idea why this is happening, because I am new to python. But anyway, here's my program:
sentence = "one two three one four one"
word = "one"
tracked = ()
n = 0
p = 0
for c in sentence:
p += 1
if n == 0 and c == word[n]:
n += 1
tracked = (p)
elif n == len(word) and c == word[n]:
print(tracked[1], tracked[2])
tracked = ()
n = 0
elif c == word[n]:
n += 1
tracked = (tracked[1], p)
else:
tracked = ()
n = 0