Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'forgive': 0.05; 'subject:Python': 0.06; 'modify': 0.07; "'a'": 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'present,': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'subject:()': 0.09; 'whichever': 0.09; '~ethan~': 0.09; 'python': 0.11; '2.7:': 0.16; 'cares': 0.16; 'dictionary,': 0.16; 'received:69.93': 0.16; 'wrote:': 0.18; 'header:User-Agent:1': 0.23; "haven't": 0.24; 'references': 0.26; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; "doesn't": 0.30; 'code': 0.31; '>>>>': 0.31; 'about.': 0.31; 'accidentally': 0.31; 'constant': 0.31; 'keys': 0.31; 'cases': 0.33; 'something': 0.35; 'but': 0.35; 'false': 0.36; 'charset:us-ascii': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'full': 0.61; 'mentioned': 0.61; 'received:173': 0.61; 'useful.': 0.68; 'subject: & ': 0.68; 'repeat': 0.74; 'ethan': 0.84; 'furman': 0.84 Date: Thu, 25 Jul 2013 06:47:08 -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: <51EF2AD8.3080105@stoneleaf.us> In-Reply-To: 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]:50266 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1374762804 news.xs4all.nl 15988 [2001:888:2000:d::a6]:46243 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:51227 On 07/24/2013 11:01 PM, alex23 wrote: > On 25/07/2013 4:31 AM, Ethan Furman wrote: >> 2) Hopefully learn something about when a view is useful. > > I haven't seeen this mentioned - forgive me if it's a repeat - but views are constant references to whichever set they > represent. > > Python 2.7: > >>>> dd = dict(a=1,b=2,c=3) >>>> keys = dd.keys() >>>> 'a' in keys > True >>>> dd['d'] = 4 >>>> 'd' in keys > False > > Python 3.3: >>>> dd = dict(a=1,b=2,c=3) >>>> keys = dd.keys() >>>> 'a' in keys > True >>>> dd['d'] = 4 >>>> 'd' in keys > True > > If part of my code is only interested in what keys or values are present, it doesn't need to be given a reference to the > full dictionary, just to whichever view it cares about. In these cases why is a view better than just using the dict? Is it a safety so the you don't accidentally modify the dict? -- ~Ethan~