Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #28850

Re: set and dict iteration

Newsgroups comp.lang.python
Date 2012-09-10 13:14 -0700
References (1 earlier) <mailman.3389.1345146609.4697.python-list@python.org> <7xy5le7cli.fsf@ruckus.brouhaha.com> <502D7E17.1070103@dejaviewphoto.com> <mailman.3405.1345160667.4697.python-list@python.org> <7xvcgi8h70.fsf@ruckus.brouhaha.com>
Message-ID <753e4641-0c61-42c0-a87d-7826be736aa6@googlegroups.com> (permalink)
Subject Re: set and dict iteration
From 88888 Dihedral <dihedral88888@googlemail.com>

Show all headers | View raw


Paul Rubin於 2012年8月17日星期五UTC+8上午9時01分39秒寫道:
> Ian Kelly <ian.g.kelly@gmail.com> writes:
> 
> > With regard to key insertion and deletion while iterating over a dict
> 
> > or set, though, there is just no good reason to be doing that
> 
> > (especially as the result is very implementation-specific), and I
> 
> > wouldn't mind a more complete low-level check against it as long as
> 
> > it's not too expensive (which is not clearly the case with the current
> 
> > suggestion at all).
> 
> 
> 
> One possible approach is to freeze the dictionary against modification
> 
> while any iterator is open on it.  You could keep a count of active
> 
> iterators in the dict structure, adjusting it whenever an iterator is
> 
> created or closed/destroyed.

If there is only one iterator of a frozen dictionary,
then nothing is saved.

But if there are manny iterators based on the same frozen dictionary, 
this approach saves a lot. 


Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: set and dict iteration 88888 Dihedral <dihedral88888@googlemail.com> - 2012-09-10 13:14 -0700

csiph-web