[Chicago] Deleting from a list or dictionary while processing it?

Lewit, Douglas d-lewit at neiu.edu
Sat Mar 25 17:59:07 EDT 2017


Hi guys,

I remember doing some of this once upon a time, but I may have forgotten
the details, so if someone could refresh my memory that would be great.

In essence, what I'm trying to do is process a list ( or perhaps a
dictionary ) BUT WHILE I'M PROCESSING IT I WANT TO MUTATE IT BY DELETING
ELEMENTS FROM IT.  Does that make sense?

( Launching Python interpreter to provide a concrete example! )

*while** my_list:*

      *for** n **in** my_list[:]:*

*            print**(n)*

            *my_list = my_list[**1**:]*


I think that's correct.... but still.... it can get a bit confusing.  Okay,
thanks for the feedback.


Best,


Douglas.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170325/16f59d01/attachment.html>


More information about the Chicago mailing list