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


Groups > comp.lang.python > #51150

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!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.013
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'explicitly': 0.05; 'subject:Python': 0.06; 'odd': 0.07; 'decision.': 0.09; 'iterate': 0.09; 'subject:()': 0.09; 'itself.': 0.14; 'benjamin': 0.16; 'choice,': 0.16; 'dict': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterates': 0.16; 'iterating': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'thu,': 0.19; 'options': 0.25; 'equivalent': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '25,': 0.31; 'implicit': 0.31; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'curious': 0.36; 'half': 0.37; 'list': 0.37; 'to:addr:python-list': 0.38; 'rather': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'either': 0.39; 'even': 0.60; 'temporary': 0.65; 'side': 0.67; 'subject: & ': 0.68; 'jul': 0.74; 'ethan': 0.84; 'furman': 0.84; 'oscar': 0.84; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=RYHc4jg1pFqVAvvTILB+ZtirNzyN7AtQm7raIEtZNEY=; b=hadJiIdSZ24lwBqR3gsS2ELtpzMpMbd36JppblR7+4ytrSro6rfsOPM2BuHiU5fC+E RCtTq0vcV/o8dLgNOelRvYC3GcGPsX4yNgVp+JiQRkolPMJ557CdUM99gOjYBfbFi94I v5pLRbX07jsQdAk04xyM+7WmmOPwKgaZlV9sbfmC7Wj/4n/o1OEmZmcNPtTDBFIqW0YS igaw0hzMK+K+EHVu3oU+Lyf/ZC3rJpcFToCKCkde6Fzs0kIbGAhAsmLXZpEiBegK805R pOBiDWpTqz1031wtwErJupBNnqbWlICRI63sMzBHLiJWiFh5YxJyxWhMDtzUG4pVG7lb +VZQ==
MIME-Version 1.0
X-Received by 10.52.103.84 with SMTP id fu20mr7837822vdb.51.1374683691003; Wed, 24 Jul 2013 09:34:51 -0700 (PDT)
In-Reply-To <51EFF957.1040707@stoneleaf.us>
References <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <CAHVvXxQGCFJe7ud+mwh4zhnq5F7xvHJX1pCtGCjMaFtjBwY=iQ@mail.gmail.com> <51EFF957.1040707@stoneleaf.us>
Date Thu, 25 Jul 2013 02:34:50 +1000
Subject Re: Python 3: dict & dict.keys()
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
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.5052.1374684136.3114.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374684136 news.xs4all.nl 15894 [2001:888:2000:d::a6]:55645
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51150

Show key headers only | View raw


On Thu, Jul 25, 2013 at 1:57 AM, Ethan Furman <ethan@stoneleaf.us> wrote:
> On 07/24/2013 05:51 AM, Oscar Benjamin wrote:
>> What do you mean? Why would you want to create a temporary list just to
>> iterate over it explicitly or implicitly (set,
>> sorted, max,...)?
>
> You wouldn't.  But you don't need .keys() for that either as you can just
> use the dict itself.

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.

ChrisA

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


Thread

Re: Python 3: dict & dict.keys() Chris Angelico <rosuav@gmail.com> - 2013-07-25 02:34 +1000

csiph-web