for loop troubles

Alex Martelli aleaxit at yahoo.com
Fri Apr 27 04:06:57 EDT 2001


"Jeff Shipman" <shippy at nmt.edu> wrote in message
news:3AE8EFCC.CEFCF61F at nmt.edu...
> I've used this method before to do funky for loop
> stuff, but for some reason, I'm getting a line skipped
> this time.
    ...
>       for line in linelist:
    ...
>                linelist.pop(j)
    ...
> doesn't. I'm assuming it must have something to
> do with my linelist.pop(j), but I do something similar
> to this in several other locations in the program
> and I've done it in other programs with no odd
> problems. Basically, I'm doing that to get rid of
> all the lines I'm passing to the recursive call.

Modifying the sequence that you're looping on while
you're looping on it will often give surprising
results.  If you do it in several other locations
and it hasn't been biting you, you may have been
lucky (or unlucky, depending on one's viewpoint:-).

I would suggest a different approach -- do a simple
loop without deletion nor recursion, just keeping
track of 'state' ("how deeply nested am I") so
you can decorate the output with the appropriate
<UL>, </UL> and <LI> tags as depth increases/
decreases/stays above 0.


Alex








More information about the Python-list mailing list