[Python-ideas] first() and last() tests in for x in y loops

Terry Reedy tjreedy at udel.edu
Tue Jul 20 23:59:07 CEST 2010


On 7/20/2010 1:03 PM, et gmail wrote:

> I could see the code looking something like this
> for item in List:
> if __first__:
> print ‘we are in the first loop’
> doSomething()
> if __last__ is False:
> print ‘,’
>
> Sorry if the formatting is a little off.

Do not use tabs when posting code.

> Does something like this already exist

I am posting an extended answer to "How to treat the first or last item 
differently" on python-list (gmane.comp.python.general) so that others 
can see and find it.

-- 
Terry Jan Reedy





More information about the Python-ideas mailing list