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


Groups > comp.lang.python > #51174

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

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.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.06; '*not*': 0.07; 'rename': 0.07; 'converted': 0.09; 'historically': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'seemed': 0.09; 'subject:()': 0.09; 'python': 0.11; 'jan': 0.12; '2.7': 0.14; 'question.': 0.14; 'hashed': 0.16; 'illustrates': 0.16; 'indirectly': 0.16; 'iterables': 0.16; 'iterated': 0.16; 'iterator': 0.16; 'keys.': 0.16; 'libraries.': 0.16; 'once.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'renaming': 0.16; 'stuff,': 0.16; 'ignore': 0.16; 'wrote:': 0.18; '3.0': 0.19; 'replacing': 0.19; 'header :User-Agent:1': 0.23; '2.x': 0.24; 'replace': 0.24; 'decide': 0.24; 'question': 0.24; 'developers': 0.25; 'equivalent': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'array': 0.29; 'thus': 0.29; 'needed.': 0.30; 'code': 0.31; 'easier': 0.31; '3.x': 0.31; 'lists?': 0.31; 'operations.': 0.31; 'stuff': 0.32; 'run': 0.32; 'possible.': 0.35; 'case,': 0.35; 'operations': 0.35; 'but': 0.35; 'functions.': 0.36; 'vice': 0.36; 'should': 0.36; 'half': 0.37; 'wrong': 0.37; 'two': 0.37; 'list': 0.37; 'clear': 0.37; 'implement': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'either': 0.39; 'received:org': 0.40; 'space': 0.40; 'how': 0.40; 'easy': 0.60; 'around.': 0.60; 'new': 0.61; 'received:173': 0.61; 'back': 0.62; 'name': 0.63; 'design,': 0.64; 'therefore,': 0.64; 'more': 0.64; 'forward': 0.65; 'latest': 0.67; 'advantages': 0.68; 'answer.': 0.68; 'subject: & ': 0.68; "'view'": 0.84; '2.7.': 0.84; 'confusing': 0.84; 'designed,': 0.84; 'duplication,': 0.84; 'received:fios.verizon.net': 0.84; 'conflicts,': 0.91
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 19:45:37 -0400
References <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <ksp2it$21p$1@ger.gmane.org> <51F01D9E.2030903@stoneleaf.us> <kspbms$atn$1@ger.gmane.org> <5B80DD153D7D744689F57F4FB69AF474185C131B@SCACMX008.exchad.jpmchase.net>
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 <5B80DD153D7D744689F57F4FB69AF474185C131B@SCACMX008.exchad.jpmchase.net>
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.5071.1374709554.3114.python-list@python.org> (permalink)
Lines 49
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374709554 news.xs4all.nl 15864 [2001:888:2000:d::a6]:33497
X-Complaints-To abuse@xs4all.nl
Path csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.astraweb.com!border5.a.newsrouter.astraweb.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:51174

Show key headers only | View raw


On 7/24/2013 4:34 PM, Prasad, Ramit wrote:

> I am still not clear on the advantage of views vs. iterators.

A1: Views are iterables that can be iterated more than once. Therefore, 
they can be passed to a function that re-iterates its inputs, or to 
multiple functions. They support 'x in view' as efficiently as possible. 
Think about how you would write the non-view equivalent of '(0,None) in 
somedict.views())'. When set-like, views support some set operations. 
For .keys, which are always set-like, these operations are easy to 
implement as dicts are based on a hashed array of keys.

Q2: What is the advantage of views vs. lists?

A2: They do not take up space that is not needed. They can be converted 
to lists, to get all the features of lists, but not vice versa.

> What makes d.viewkeys() better than d.iterkeys()? Why did they decide
> not to rename d.iterkeys() to d.keys() and instead use d.viewkeys()?

This is historically the wrong way to phrase the question. The 2.7 
.viewxyz methods were *not* used to make the 3.x .xyz methods. It was 
the other way around. 3.0 came out with view methods replacing both list 
and iter methods just after 2.6, after a couple of years of design, and 
a year and a half before 2.7. The view methods were backported from 3.1 
to 2.7, with 'view' added to the name to avoid name conflicts, to make 
it easier to write code that would either run on both 2.7 and 3.x or be 
converted with 2to3.

A better question is: 'When 3.0 was designed, why were views invented 
for the .xyz methods rather than just renaming the .iterxyz methods. The 
advantages given above are the answer. View methods replace both list 
and iterator methods and are more flexible than either and directly or 
indirectly have all the advantages of both.

My question is why some people are fussing so much because Python 
developers gave them one thing that is better than either of the two 
things it replaces?

The mis-phrased question above illustrates why people new to Python 
should use the latest 3.x and ignore 2.x unless they must use 2.x 
libraries. 2.7 has all the old stuff, for back compatibility, and as 
much of the new stuff in 3.1 as seemed sensible, for forward 
compatibility. Thus it has lots of confusing duplication, and in this 
case, triplication

-- 
Terry Jan Reedy

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


Thread

Re: Python 3: dict & dict.keys() Terry Reedy <tjreedy@udel.edu> - 2013-07-24 19:45 -0400

csiph-web