Return-Path: 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 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: <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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 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~