This is the code to do the opposite of what I want to do. This adds a word per line but I want to remove a word per line. Is there a way to reverse this loop?
lst = input("Enter a phrase: ")
word = lst.split()
for i in range(len(word)):
print(' '.join(word[:i]))
print(lst)
>Solution :
You can change your range to loop backwards:
lst = input("Enter a phrase: ")
word = lst.split()
for i in range(len(word), 0, -1):
print(' '.join(word[:i]))
print(lst)
Displays:
Enter a phrase: I like pizza
I like pizza
I like
I
I like pizza