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


Groups > comp.lang.python > #51179

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

Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'explicitly': 0.05; 'subject:Python': 0.06; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'keys,': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'subject:()': 0.09; 'window.': 0.09; '~ethan~': 0.09; 'python': 0.11; '"in': 0.16; 'effect.': 0.16; 'license.': 0.16; 'received:69.93': 0.16; 'wrote:': 0.18; "hasn't": 0.19; "python's": 0.19; 'header:User-Agent:1': 0.23; 'header:In-Reply- To:1': 0.27; 'went': 0.31; '-0700,': 0.31; 'changed.': 0.31; "d'aprano": 0.31; 'dramatic': 0.31; 'keys': 0.31; 'steven': 0.31; 'not.': 0.33; 'surely': 0.36; 'charset:us-ascii': 0.36; 'list': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'even': 0.60; 'received:173': 0.61; 'subject: & ': 0.68; 'jul': 0.74; 'repeat': 0.74; "'view'": 0.84; 'actually,': 0.84; 'ethan': 0.84; 'furman': 0.84; '2013': 0.98
Date Wed, 24 Jul 2013 17:59:43 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1
MIME-Version 1.0
To python-list@python.org
Subject Re: Python 3: dict & dict.keys()
References <mailman.5024.1374628577.3114.python-list@python.org> <51ef37e3$0$29971$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <51ef37e3$0$29971$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender ([173.12.184.233]) [173.12.184.233]:47401
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 1
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
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.5075.1374713993.3114.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1374713993 news.xs4all.nl 15936 [2001:888:2000:d::a6]:57985
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!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Xref csiph.com comp.lang.python:51179

Show key headers only | View raw


On 07/23/2013 07:11 PM, Steven D'Aprano wrote:
> On Tue, 23 Jul 2013 18:16:08 -0700, Ethan Furman wrote:
>>
>> So now, in Python 3, .keys(), .values(), even .items() all return these
>> 'view' thingies.
>>
>> And everything I thought I knew about when to use one or the other went
>> out the window.
>
> Surely not. The fundamental behaviour of Python's data model hasn't
> changed.

Poetic effect.  Dramatic license.  Blah blah.  ;)


> Repeat after me: "In Python 2, d.keys() returns a list of keys, so if I
> want a list of keys in Python 3, call list explicitly list(d.keys())."

Actually, I would recommend `list(d)`, which also works the same in both 2 and 3.

--
~Ethan~

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


Thread

Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-23 18:16 -0700
  Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-24 02:11 +0000
    Re: Python 3: dict & dict.keys() Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-24 09:02 -0600
    Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-24 17:59 -0700
      Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-25 05:57 +0000
    Re: Python 3: dict & dict.keys() Ben Finney <ben+python@benfinney.id.au> - 2013-07-25 12:20 +1000

csiph-web