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


Groups > comp.lang.python > #64329

Re: Documentation of dict views change request

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'nasty': 0.07; 'returns,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'jan': 0.12; 'changes': 0.15; "('c',": 0.16; '(which,': 0.16; '1),': 0.16; '3)]': 0.16; '8:40': 0.16; "[('a',": 0.16; 'charles': 0.16; 'dict': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'read-only.': 0.16; 'roy': 0.16; 'shallow': 0.16; 'values?': 0.16; 'wording': 0.16; 'wrote:': 0.18; 'subject:request': 0.19; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'documented': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'returned': 0.30; 'message-id:@mail.gmail.com': 0.30; 'are.': 0.31; 'could': 0.34; 'no,': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'method': 0.36; 'list': 0.37; 'expected': 0.38; 'lists.': 0.38; 'itself': 0.39; 'read': 0.60; 'affect': 0.61; "you're": 0.61; 'talking': 0.65; '20,': 0.68; 'smith': 0.68; 'subject': 0.69; 'article': 0.77; 'p.s.:': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=2S3VASIIpBWVbxLJQLstIxD9RwrIZXTY6Tbc0t0sfXA=; b=N9V+fqcsHsyAt0jWLpPwpgubLhUj+prdbX48rU60IZueGi/5nBd/BV2t0UIJf7f2M8 tvuM+kScJNwl6WStvJSHVVAXbahEt7GXi0xlayxy0gWeqzSGSlOg2/AcQelUlFFdtDNk ytZun/N6XX+3kr4iqbjdVAm/FpNmNqFNXlelpCSwgV+Sucv7wgAe5wdbGGSxotkhJnx7 SKNOXSIdk9Lh+zo5l0sJKRlv8BymO0f43iRa7Hk1w9nPwRGZyuhjgvM9xFxYJJ9PL+Tk SY9d7F41YlT3Tgtv6ZBpnsoaRJOKnj03alzT8U0lItcbTRfzsoOmXFPBSKb4fFACDCik CDxQ==
MIME-Version 1.0
X-Received by 10.68.201.71 with SMTP id jy7mr15016117pbc.47.1390168602494; Sun, 19 Jan 2014 13:56:42 -0800 (PST)
In-Reply-To <roy-B69DE3.03105820012014@news.panix.com>
References <mailman.5728.1390166846.18130.python-list@python.org> <roy-B69DE3.03105820012014@news.panix.com>
Date Mon, 20 Jan 2014 08:56:42 +1100
Subject Re: Documentation of dict views change request
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.5730.1390168611.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1390168611 news.xs4all.nl 2855 [2001:888:2000:d::a6]:40419
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:64329

Show key headers only | View raw


On Mon, Jan 20, 2014 at 8:40 AM, Roy Smith <roy@panix.com> wrote:
> In article <mailman.5728.1390166846.18130.python-list@python.org>,
>  Charles Hixson <charleshixsn@earthlink.net> wrote:
>
>> Could it please be clearly documented that keys(), values(), and items()
>> are not writeable.
>
> We'll, technically, they are.
>
> Of course, this only changes the list that keys() returns, it doesn't
> affect the dictionary itself (which, I assume, is what you were really
> talking about).

In Python 3, they return views, not lists. So they really are read-only.

On Mon, Jan 20, 2014 at 8:26 AM, Charles Hixson
<charleshixsn@earthlink.net> wrote:
> P.S.:  Is it reasonable to return the items() of a dict in order to pass a
> read only copy of the values?

No, because it isn't a copy. At least, not in Python 3; if you're
using Python 2, then the wording of your subject line is inaccurate,
see above.

>>> d = {"a":1,"b":2,"c":3}
>>> i = d.items()
>>> del d["b"]
>>> list(i)
[('a', 1), ('c', 3)]

If you returned i from a function and expected it to be a copy, you'd
be in for a nasty shock. Try the .copy() method for a shallow copy, or
look up deepcopy if you need a recursive copy.

ChrisA

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


Thread

Documentation of dict views change request Charles Hixson <charleshixsn@earthlink.net> - 2014-01-19 13:26 -0800
  Re: Documentation of dict views change request Roy Smith <roy@panix.com> - 2014-01-20 03:10 +0530
    Re: Documentation of dict views change request Chris Angelico <rosuav@gmail.com> - 2014-01-20 08:56 +1100

csiph-web