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


Groups > comp.lang.python > #51152

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

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'odd': 0.07; 'decision.': 0.09; 'default.': 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; 'jan': 0.12; 'books': 0.15; 'choice,': 0.16; 'dict': 0.16; 'iterates': 0.16; 'iterating': 0.16; 'keyed': 0.16; 'reason.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'items.': 0.19; 'header:User-Agent:1': 0.23; 'options': 0.25; 'equivalent': 0.26; 'first,': 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; 'produces': 0.31; 'second,': 0.31; "can't": 0.35; 'common': 0.35; 'equal': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'books,': 0.36; 'curious': 0.36; 'should': 0.36; 'half': 0.37; 'two': 0.37; 'to:addr:python-list': 0.38; 'fact': 0.38; 'pm,': 0.38; 'rather': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'even': 0.60; 'eventually': 0.60; 'received:173': 0.61; 'such': 0.63; 'more': 0.64; 'phone': 0.66; 'side': 0.67; 'subject: & ': 0.68; 'default': 0.69; 'coupled': 0.84; 'dict.': 0.84; 'received:fios.verizon.net': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: Python 3: dict & dict.keys()
Date Wed, 24 Jul 2013 13:17:12 -0400
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=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130620 Thunderbird/17.0.7
In-Reply-To <CAPTjJmrnN-13PpKv7LTv6tTH1Tp_zdLj_tsy4NUyDwbm-esB7Q@mail.gmail.com>
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.5054.1374686249.3114.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374686249 news.xs4all.nl 15870 [2001:888:2000:d::a6]:38159
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51152

Show key headers only | View raw


On 7/24/2013 12:34 PM, Chris Angelico wrote:

> 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.

Both were considered and I think there were and are two somewhat-linked 
practical reasons. First, iterating over keys in more common than 
iterating over items. The more common one should be the default.

Second, people ask much more often if 'key' is in dict than if 'key, 
value' is in dict. This is true as well for keyed reference books such 
as phone books, dictionaries, encyclopedias, and for the same reason. 
This is  coupled with the fact that the default meaning of 'item in 
collection' is that iterating over 'collection' eventually produces 
'item' or a value equal to 'item'.

-- 
Terry Jan Reedy

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


Thread

Re: Python 3: dict & dict.keys() Terry Reedy <tjreedy@udel.edu> - 2013-07-24 13:17 -0400
  Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-25 05:52 +0000

csiph-web