How to detect the last element in a for loop

Tom Verbeure tom.verbeure at verizon.no.sp.am.net
Sun Jul 28 13:04:27 EDT 2002


> I did not follow this thread, I may be missing something, but why not:
> 
>     for a in myList:
>          do_stuff(a)
>     special_stuff(a)
> 
> taking advantage on the fact that `a' keeps the last value it received?

Then what about this?

for a in myList:
    if last_one:
        special_stuff
    do_stuff
Tom




More information about the Python-list mailing list