How to loop through all but the last item of a list? October 18, 2022 by Tarik for x in y[:-1] If y is a generator, then the above will not work.