Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64327
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Documentation of dict views change request |
| Date | 2014-01-20 03:10 +0530 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-B69DE3.03105820012014@news.panix.com> (permalink) |
| References | <mailman.5728.1390166846.18130.python-list@python.org> |
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.
>>> d = {'foo': 1, 'bar':2}
>>> k = d.keys()
>>> k
['foo', 'bar']
>>> k[0] = "some other key"
>>> k
['some other key', 'bar']
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).
Think this one through. How *could* altering what keys() returns
possibly affect the dict? If it did, that means you could do something
like:
some_dict.keys().append("some other key")
what would that mean? You've added a key, but what's the corresponding
value? I will admit, the picture becomes a bit fuzzier if you consider:
some_dict.items().append(("some other key", 42))
which you could at least imagine would affect the underlying dict.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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