How to loop through all but the last item of a list?

for x in y[:-1]

If y is a generator, then the above will not work.

Leave a Comment