Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27249
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!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 | <castironpi@gmail.com> |
| 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; '16,': 0.03; '(python': 0.05; 'repeated': 0.07; '40,': 0.09; 'subject:set': 0.09; 'to:addr:comp.lang.python': 0.09; 'underlying': 0.09; 'cc:addr:python-list': 0.10; 'aug': 0.13; '12]': 0.16; '24,': 0.16; '24]': 0.16; 'element.': 0.16; 'iteration,': 0.16; 'iterator': 0.16; 'itertools': 0.16; 'resize': 0.16; 'later': 0.16; 'wrote:': 0.17; 'comparing': 0.17; 'element': 0.17; 'thu,': 0.17; '>>>': 0.18; 'import': 0.21; 'not,': 0.21; 'occurs': 0.22; 'originally': 0.23; 'cc:no real name:2**0': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'appear': 0.26; 'cc:addr:gmail.com': 0.27; '>>>>': 0.29; 'hash': 0.29; 'table,': 0.29; 'thursday,': 0.30; '11,': 0.33; 'curious': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'item': 0.37; 'received:209': 0.37; 'well.': 0.37; 'subject:: ': 0.38; 'remove': 0.61; 'between': 0.63; 'more': 0.63; 'here': 0.65; 'therefore': 0.65; 'august': 0.66; 'hey,': 0.72; 'examples.': 0.84; 'sixth': 0.84; 'items,': 0.91; 'received:209.85.220.184': 0.91 |
| Newsgroups | comp.lang.python |
| Date | Fri, 17 Aug 2012 10:47:16 -0700 (PDT) |
| In-Reply-To | <mailman.3403.1345158493.4697.python-list@python.org> |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=67.184.78.189; posting-account=MQ3pigoAAACeFzUFjVAePnOjOJMNlvq9 |
| References | <b8dd3aca-2a87-4124-ad6e-66a8720af99a@googlegroups.com> <CALwzidkR2hEOu7Y4HhUti5S4HJqAtsDf_V6h4RHt-v094T4_Ug@mail.gmail.com> <mailman.3403.1345158493.4697.python-list@python.org> |
| User-Agent | G2/1.0 |
| X-Google-Web-Client | true |
| X-Google-IP | 67.184.78.189 |
| MIME-Version | 1.0 |
| Subject | Re: set and dict iteration |
| From | Aaron Brady <castironpi@gmail.com> |
| To | comp.lang.python@googlegroups.com |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org, Aaron Brady <castironpi@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| 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> |
| Message-ID | <mailman.3420.1345226405.4697.python-list@python.org> (permalink) |
| Lines | 90 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1345226405 news.xs4all.nl 6961 [2001:888:2000:d::a6]:52436 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:27249 |
Show key headers only | View raw
On Thursday, August 16, 2012 6:07:40 PM UTC-5, Ian wrote:
> On Thu, Aug 16, 2012 at 4:55 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>
> > On Thu, Aug 16, 2012 at 12:00 PM, Aaron Brady <castironpi@gmail.com> wrote:
>
> >> 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:
>
> >
>
> > It can be more than just the new element. For example, here the
>
> > entire set is repeated (Python 3.2):
>
> >
>
> >>>> s = set(range(8, 13))
>
> >>>> it = iter(s)
>
> >>>> from itertools import islice
>
> >>>> list(islice(it, 5)) # avoid exhausting the iterator
>
> > [8, 9, 10, 11, 12]
>
> >>>> s.add(13)
>
> >>>> s.remove(13)
>
> >>>> list(it)
>
> > [8, 9, 10, 11, 12]
>
> >
>
> > This occurs because the addition of the sixth item triggers a resize
>
> > of the underlying hash table, and the existing items, which were
>
> > originally in slots 0-4, are now in slots 8-12.
>
>
>
> Another curious example:
>
>
>
> >>> s = set(range(8, 48, 8))
>
> >>> s
>
> {8, 16, 40, 24, 32}
>
> >>> it = iter(s)
>
> >>> from itertools import islice
>
> >>> list(islice(it, 4))
>
> [8, 16, 40, 24]
>
> >>> s.add(48)
>
> >>> s.remove(48)
>
> >>> list(it)
>
> [8, 16, 40, 24]
>
>
>
> Hey, what happened to 32?
Good examples. The former occurs without the 'islice' as well.
s= set( range( 8, 13 ) )
it= iter( s )
print( [ next( it ) for _ in range( 5 ) ] )
s.add( 13 )
s.remove( 13 )
print( [ next( it ) for _ in range( 5 ) ] )
Output:
[8, 9, 10, 11, 12]
[8, 9, 10, 11, 12]
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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