Let's say I have a list ''Here Comes The Sun And I Say It Is Alright''
and I need to remove every third word from the string and replace it with the previous one so the output will be ''Here Comes Comes Sun And And Say It It Alright''. The teacher advised us to use '%'.. but I tried many different options like when (n%2!=0).. and it still didn't work.
It would be really nice if you'll help me :)
I think that is what you need:
s = 'Here Comes The Sun And I Say It Is Alright'.split() for i in range(2, len(s), 3): s[i] = s[i - 1] print(' '.join(s)) # 'Here Comes Comes Sun And And Say It It Alright'