need insight...

Suchandra Thapa ssthapa at midway.uchicago.edu
Sat Jun 24 18:54:50 EDT 2000


Stephen Hansen <stephen at cerebralmaelstrom.com> wrote:
>    The problem is that you really do not want to change the sequence you're
>using in 'for' -- the documentation, if memory serves, shows an example of
>precisely why. You'll want to make a copy of it to iterate through.. like;
>
>for item in cwd[:]:
>    ...
>    cwd.remove(item)
>
>Like that..see? The [:] slice copies the whole sequence.
>
    Actually I don't think code even needs to make a copy or have the
cwd.remove(item) call since it deletes cwd right after the for loop.
That should save a little space and speed up the code a bit.

-- 
------------------------------------------------------------------

Suchandra S. Thapa 
s-thapa at uchicago.edu

------------------------------------------------------------------



More information about the Python-list mailing list