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


Groups > comp.lang.python > #51167

Re: Python 3: dict & dict.keys()

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1374700033; bh=OZpD3KD2NGVA6AAO5EkZEF2ENnSMYICZKBFo5MvFVxg=; h=To:From:Subject:Date:Message-ID:References:Mime-Version: Content-Type:Content-Transfer-Encoding:In-Reply-To; b=Yd9OV9MZMC5Mwi3EJCSeyuEflunubedP2FS/Z3LdtuNcay2cXQ5vUsXTj7eKlBHRh UCx+VDSMpRwuIXHhEzrceyx3+BKaSBQH497ILU2Wq012Pq4b/B84TUiiZ8qnqeunnw RFd079l6naOkvvapojgb3rz3kLgIVuMhu5MhzE4Y=
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; 'odd': 0.07; 'decision.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:()': 0.09; '"in"': 0.16; '(key,': 0.16; 'choice,': 0.16; 'dict': 0.16; 'from:name:christian heimes': 0.16; 'iterates': 0.16; 'iterating': 0.16; 'iterator': 0.16; 'operates': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'surprising': 0.16; 'from:addr:python.org': 0.16; 'obviously': 0.18; 'header:User- Agent:1': 0.23; 'options': 0.25; 'equivalent': 0.26; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; "i'm": 0.30; 'implicit': 0.31; 'keys': 0.31; "can't": 0.35; 'but': 0.35; 'version': 0.36; 'curious': 0.36; 'half': 0.37; 'christian': 0.38; 'checks': 0.38; 'to:addr:python- list': 0.38; 'rather': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'even': 0.60; 'side': 0.67; 'subject: & ': 0.68
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Christian Heimes <christian@python.org>
Subject Re: Python 3: dict & dict.keys()
Date Wed, 24 Jul 2013 23:06:56 +0200
References <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <CAHVvXxQGCFJe7ud+mwh4zhnq5F7xvHJX1pCtGCjMaFtjBwY=iQ@mail.gmail.com> <51EFF957.1040707@stoneleaf.us> <CAPTjJmrnN-13PpKv7LTv6tTH1Tp_zdLj_tsy4NUyDwbm-esB7Q@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host f049107027.adsl.alicedsl.de
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6
In-Reply-To <CAPTjJmrnN-13PpKv7LTv6tTH1Tp_zdLj_tsy4NUyDwbm-esB7Q@mail.gmail.com>
X-Enigmail-Version 1.4.6
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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.5065.1374700034.3114.python-list@python.org> (permalink)
Lines 21
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374700034 news.xs4all.nl 15884 [2001:888:2000:d::a6]:51999
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51167

Show key headers only | View raw


Am 24.07.2013 18:34, schrieb Chris Angelico:
> Side point: Why is iterating over a dict equivalent to .keys() rather
> than .items()? It feels odd that, with both options viable, the
> implicit version iterates over half the dict instead of all of it.
> Obviously it can't be changed now, even if .items() were the better
> choice, but I'm curious as to the reason for the decision.

Consider this:

if key in dict:
    ...

for key in dict:
   ...

It would be rather surprising if "in" as containment checks operates on
keys and "in" as iterator returns (key, value) tuples.

Christian

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


Thread

Re: Python 3: dict & dict.keys() Christian Heimes <christian@python.org> - 2013-07-24 23:06 +0200

csiph-web