Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #27212
| 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 | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; '16,': 0.03; '(python': 0.05; 'repeated': 0.07; '40,': 0.09; 'received :mail-lpp01m010-f46.google.com': 0.09; 'subject:set': 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; 'cc:2**0': 0.23; 'originally': 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'appear': 0.26; 'message-id:@mail.gmail.com': 0.27; '>>>>': 0.29; 'hash': 0.29; 'table,': 0.29; 'received:209.85.215.46': 0.30; '11,': 0.33; 'curious': 0.33; 'another': 0.33; 'received:google.com': 0.34; 'pm,': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'item': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'header:Received:5': 0.40; 'remove': 0.61; 'between': 0.63; 'more': 0.63; 'here': 0.65; 'therefore': 0.65; 'hey,': 0.72; 'sixth': 0.84; 'items,': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=MScSXyyaO18agmDfE/6ATrJrRn9nGk2GSkNp8e0VkQI=; b=vcO/A6QxWXzBJs+HiP51ddrdTrtVWvxjSvsf0cH4zXFU4NFIT60Ces/wGBzD0jXGYO Ef2Ptt38XbmvK7t8vQfcxSpFSl/Mih56usYVskRFf+65GQcapldwjDCaeOSgp9L3nBph 8TtfbWWmfX5QItk5LgpUVicqBzabaSAWxM3c/ZO9dTGMh2Ym57fDFVsrrgA28vJZhzaE HWN1ZpxThmVBN+9TW5un9EQONrWTleCwQxY0NNnK2VFKFQpSUY+9w88pdGxVNTQfg4WH vAr3LOMLLunq8/wnxwhLV4wZ/45l2s2rECLqxZ9SOEATgl6l5furZv/5vKtlDM2jcPGc 75/A== |
| MIME-Version | 1.0 |
| In-Reply-To | <CALwzidkR2hEOu7Y4HhUti5S4HJqAtsDf_V6h4RHt-v094T4_Ug@mail.gmail.com> |
| References | <b8dd3aca-2a87-4124-ad6e-66a8720af99a@googlegroups.com> <CALwzidkR2hEOu7Y4HhUti5S4HJqAtsDf_V6h4RHt-v094T4_Ug@mail.gmail.com> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Thu, 16 Aug 2012 17:07:40 -0600 |
| Subject | Re: set and dict iteration |
| To | Aaron Brady <castironpi@gmail.com> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| Cc | python-list@python.org |
| 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> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3403.1345158493.4697.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1345158493 news.xs4all.nl 6879 [2001:888:2000:d::a6]:51920 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:27212 |
Show key headers only | View raw
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?
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