On Oct 12, 11:58 am, Florian Lindner <[EMAIL PROTECTED]> wrote: > Hello, > can I determine somehow if the iteration on a list of values is the last > iteration? > > Example: > > for i in [1, 2, 3]: > if last_iteration: > print i*i > else: > print i
Yes, either use enumerate or just stop the loop early and deal with the last element outside the loop. xs = [1, 2, 3] for x in xs[:-1]: print x print xs[-1] * xs[-1] -- Paul Hankin -- http://mail.python.org/mailman/listinfo/python-list