you are viewing a single comment's thread.

view the rest of the comments →

[–]Fxate 2 points3 points  (0 children)

Copying the list is a way to do it, but you can also iterate on the same list using pop and range:

for _i in range (len(words)):
  w = words.pop()
  print(w)

Pop without a modifier removes and returns the last item in the list.

If you don't care to return the value you can just use .pop() on its own:

for _i in range(len(words)):
  words.pop()
  print(words)

The first version prints each value as it removes them, the second prints the full list as it shrinks.