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


Groups > comp.lang.python > #51227

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

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 <ethan@stoneleaf.us>
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 <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 <51EF2AD8.3080105@stoneleaf.us> <ksnrr9$k4t$1@ger.gmane.org> <ksp2it$21p$1@ger.gmane.org> <mailman.5061.1374692206.3114.python-list@python.org> <ksqeju$5s7$1@dont-email.me>
In-Reply-To <ksqeju$5s7$1@dont-email.me>
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 <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.5102.1374762804.3114.python-list@python.org> (permalink)
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

Show key headers only | View raw


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~

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


Thread

Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-24 11:31 -0700
  Re: Python 3: dict & dict.keys() alex23 <wuwei23@gmail.com> - 2013-07-25 16:01 +1000
    Re: Python 3: dict & dict.keys() Ethan Furman <ethan@stoneleaf.us> - 2013-07-25 06:47 -0700
  Re: Python 3: dict & dict.keys() Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-25 07:04 +0000
    Re: Python 3: dict & dict.keys() Chris Angelico <rosuav@gmail.com> - 2013-07-25 18:02 +1000
    Re: Python 3: dict & dict.keys() Peter Otten <__peter__@web.de> - 2013-07-25 10:13 +0200
    Re: Python 3: dict & dict.keys() Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-25 09:53 -0600
    Re: Python 3: dict & dict.keys() Peter Otten <__peter__@web.de> - 2013-07-25 18:25 +0200

csiph-web