I'm working on a project for my Python course and I'm still pretty new to coding in general. I'm having issues with one of the snippets of my code. I'm trying to make Python find every instance of the word "the" (or any input word really, it doesn't matter.) and return the word immediately after it. I am able to make it return the word after "the", but it stops after one instance when I need it to scan the entire list.
Here is my code:
the_list=['the']
animal_list=['the', 'cat', 'the', 'dog', 'the', 'axolotl']
for the_list in animal_list:
nextword=animal_list[animal_list.index("the")+1]
continue
print(nextword)
All I'm returning is cat
whereas dog
and axolotl
should pop up as well. I tried using a for loop and a continue
in order to make the code go through the same process for dog
and axolotl
, but it didn't work.