A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2016-April/144218.html below:

[Python-Dev] RFC: PEP 509: Add a private version to dict

[Python-Dev] RFC: PEP 509: Add a private version to dict [Python-Dev] RFC: PEP 509: Add a private version to dictRandom832 random832 at fastmail.com
Fri Apr 15 17:07:26 EDT 2016
On Fri, Apr 15, 2016, at 16:41, Victor Stinner wrote:
> If the dictionary values are modified during the loop, the dict
> version is increased. But it's allowed to modify values when you
> iterate on *keys*.

Why is iterating over items different from iterating over keys?

in other words, why do I have to write:

for k in dict:
    v = dict[k]
    ...do some stuff...
    dict[k] = something

rather than

for k, v in dict.items():
    ...do some stuff...
    dict[k] = something


It's not clear why the latter is something you want to prevent.
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4