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

Joshua Herman zitterbewegung at gmail.com
Wed Mar 29 14:50:50 EDT 2017


If you use a dictionary and not an ordered dictionary the order that you
insert the elements will not be preserved .
On Mon, Mar 27, 2017 at 4:28 PM Dan O'Day <4n6.listserv at gmail.com> wrote:

> Just be careful if relying on specific list indices after that, as the
> elements' positions will change.
>
> Dan
>
>
> On Sat, Mar 25, 2017 at 5:07 PM, Jordan Bettis <jordanb at hafd.org> wrote:
> > If you're trying to use a list as a stack you can just use list.pop:
> >
> > In [1]: my_stack = [1,2,3,4,5,6]
> >
> > In [2]: while len(my_stack) > 0:
> >    ...:     print(l.pop())
> >    ...:
> > 6
> > 5
> > 4
> > 3
> > 2
> > 1
> >
> >
> > On 03/25/2017 04:59 PM, Lewit, Douglas wrote:
> >
> > 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.
> >
> >
> >
> >
> > _______________________________________________
> > Chicago mailing list
> > Chicago at python.org
> > https://mail.python.org/mailman/listinfo/chicago
> >
> >
> >
> > _______________________________________________
> > Chicago mailing list
> > Chicago at python.org
> > https://mail.python.org/mailman/listinfo/chicago
> >
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20170329/3045b1b6/attachment.html>


More information about the Chicago mailing list