[Python-ideas] Variations on a loop

Bruce Leban bruce at leapyear.org
Sat Aug 30 20:32:35 CEST 2008

On Sat, Aug 30, 2008 at 10:56 AM, Arnaud Delobelle
<arnodel at googlemail.com>wrote:

> Finally, my function works gracefully with nested loops:
> for i, i_last in flaglast(items):
>    for j, j_last in flaglast(jtems):
>        ...
> without the need for a 'named loop', about which I feel very circumspect.

Unfortunately, your function has to get the N+1st item before the body
processes the Nth element so if getting the elements has side effects and
the body might break, then this changes the behavior of the loop. With an
explicit call to an <is this the last> function, we know exactly when it
will peek ahead in the list.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080830/245077fd/attachment.html>

More information about the Python-ideas mailing list