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


Groups > comp.lang.python > #27195

Re: set and dict iteration

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <d@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; "'''": 0.09; 'behave': 0.09; 'defined.': 0.09; 'docs.': 0.09; 'iterate': 0.09; 'subject:set': 0.09; 'bug': 0.10; 'cc:addr:python-list': 0.10; 'static': 0.13; 'modification': 0.15; '"by': 0.16; 'code?': 0.16; 'defined;': 0.16; 'enough.': 0.16; 'entries.': 0.16; 'iterating': 0.16; 'iteration': 0.16; 'iteration,': 0.16; 'runtimeerror': 0.16; 'later': 0.16; 'wrote:': 0.17; 'comparing': 0.17; 'detect': 0.17; 'element': 0.17; 'url:dev': 0.17; 'error.': 0.21; 'not,': 0.21; 'regardless': 0.21; 'bug?': 0.22; 'doc': 0.22; "user's": 0.22; 'cc:2**0': 0.23; 'sets': 0.23; 'raise': 0.24; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header :In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'appear': 0.26; 'continuing': 0.27; 'entries': 0.27; 'set.': 0.27; 'behavior.': 0.29; 'dictionary': 0.29; 'hash': 0.29; 'problem.': 0.32; 'url:python': 0.32; 'structure': 0.32; 'another': 0.33; 'clear': 0.35; 'fail': 0.35; 'pm,': 0.35; "won't": 0.35; 'add': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'should': 0.36; 'why': 0.37; 'data': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'received:192': 0.39; 'hello,': 0.39; 'received:192.168': 0.40; 'skip:u 10': 0.60; 'remove': 0.61; 'between': 0.63; 'behavior': 0.64; 'therefore': 0.65; 'header:Reply-To:1': 0.68; 'protect': 0.69; 'received:74.208': 0.71; 'reply-to:no real name:2**0': 0.72; 'forced': 0.84; 'observed': 0.84; 'received:74.208.4.194': 0.84
Date Thu, 16 Aug 2012 15:49:39 -0400
From Dave Angel <d@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0
MIME-Version 1.0
To Aaron Brady <castironpi@gmail.com>
Subject Re: set and dict iteration
References <b8dd3aca-2a87-4124-ad6e-66a8720af99a@googlegroups.com>
In-Reply-To <b8dd3aca-2a87-4124-ad6e-66a8720af99a@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Provags-ID V02:K0:FgHWooMGWb7PsIcjrOShJzB/vBslzXZRfDyl7LSpOP9 0sjgNsWuOXtKylRcxxqqLkQKe6xVIyGR9UcGlaWTYUWXycc8UA LvLJT3ydf8p0O4CaRCKrDiycO18lcjFKPvF8pp3hg6L3o3PTr7 0TIN1O97MPsz1Vptfws2aWzWHq02hGlZk4qdXhXjWTw2w8dqoP WthYq3k3PTuUTN/gCXLqt+/cdRYDsh2KEyvqCzFQqlT0fAGNWQ jblIJO29BymmCmxSk7f0m3qGHPVrgNyJGUx731GqWOBVX1RZt9 h95ll8axoKnoa+UTsX6PyEYHQTHyax9TPz/kaXsu+repxuXCg= =
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To d@davea.name
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3389.1345146609.4697.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345146609 news.xs4all.nl 6987 [2001:888:2000:d::a6]:45330
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27195

Show key headers only | View raw


On 08/16/2012 02:00 PM, Aaron Brady wrote:
> Hello,
>
> I observed an inconsistency in the behavior of 'set' and 'dict' iterators.  It is "by design" according to the docs.
>
> '''
> http://docs.python.org/dev/library/stdtypes.html#dict-views
>
> iter(dictview).  Iterating views while adding or deleting entries in the dictionary may raise a RuntimeError or fail to iterate over all entries.
> '''
>
> The 'set' has the same behavior.  Iteration might also complete successfully.
>
> The inconsistency is, if we remove an element from a set and add another during iteration, the new element might appear later in the iteration, and might not, depending on the hash code; therefore comparing the size of the set between iterations isn't adequate.  Example:
> <SNIP>
>
>
> Iteration should behave the same regardless of the contents of the set.  Continuing iteration over sets and dicts after a modification isn't defined; it should unconditionally raise an error.

Why is it the iterator's job to protect against the user's  bug?  The
doc is clear enough.  If you don't change the collection, you won't have
a problem.

> <SNIP more details>.

Everything else is implementation defined.  Why should an implementation
be forced to have ANY extra data structure to detect a static bug in the
caller's code?



-- 

DaveA

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


Thread

set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-16 11:00 -0700
  Re: set and dict iteration Dave Angel <d@davea.name> - 2012-08-16 15:49 -0400
    Re: set and dict iteration Paul Rubin <no.email@nospam.invalid> - 2012-08-16 14:26 -0700
      Re: set and dict iteration Dave Angel <davea@dejaviewphoto.com> - 2012-08-16 19:11 -0400
        Re: set and dict iteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-17 02:24 +0000
          Re: set and dict iteration Paul Rubin <no.email@nospam.invalid> - 2012-08-16 19:30 -0700
            Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-17 11:11 -0700
          Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-17 11:37 -0700
            Re: set and dict iteration Chris Angelico <rosuav@gmail.com> - 2012-08-18 07:57 +1000
              Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-18 13:29 -0700
              Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-18 13:29 -0700
                Re: set and dict iteration MRAB <python@mrabarnett.plus.com> - 2012-08-18 23:14 +0100
                Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-18 19:28 -0700
                Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-23 09:49 -0700
                Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-23 09:49 -0700
                Re: set and dict iteration Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-23 18:11 +0000
                Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-18 19:28 -0700
      Re: set and dict iteration Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-16 17:43 -0600
        Re: set and dict iteration Paul Rubin <no.email@nospam.invalid> - 2012-08-16 18:01 -0700
          Re: set and dict iteration Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-08-17 13:16 +0200
          Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-17 11:03 -0700
  Re: set and dict iteration Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-16 16:55 -0600
  Re: set and dict iteration Ian Kelly <ian.g.kelly@gmail.com> - 2012-08-16 17:07 -0600
    Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-17 10:47 -0700
    Re: set and dict iteration Aaron Brady <castironpi@gmail.com> - 2012-08-17 10:47 -0700

csiph-web