mirror of
https://github.com/python/cpython.git
synced 2025-11-27 13:45:25 +00:00
bpo-40552 Add 'users' variable in code sample (tutorial 4.2). (GH-19992)
* Add 'users' variable in code sample. * 📜🤖 Added by blurb_it. Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
This commit is contained in:
parent
b5cc2089cc
commit
6fad3e6b49
2 changed files with 5 additions and 0 deletions
|
|
@ -70,6 +70,9 @@ Code that modifies a collection while iterating over that same collection can
|
||||||
be tricky to get right. Instead, it is usually more straight-forward to loop
|
be tricky to get right. Instead, it is usually more straight-forward to loop
|
||||||
over a copy of the collection or to create a new collection::
|
over a copy of the collection or to create a new collection::
|
||||||
|
|
||||||
|
# Create a sample collection
|
||||||
|
users = {'Hans': 'active', 'Éléonore': 'inactive', '景太郎': 'active'}
|
||||||
|
|
||||||
# Strategy: Iterate over a copy
|
# Strategy: Iterate over a copy
|
||||||
for user, status in users.copy().items():
|
for user, status in users.copy().items():
|
||||||
if status == 'inactive':
|
if status == 'inactive':
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix in tutorial section 4.2.
|
||||||
|
Code snippet is now correct.
|
||||||
Loading…
Add table
Add a link
Reference in a new issue