Example doesn't work
I'm learning on Python 3.8 (32-bit) on a Windows-10 machine. In Section 4.2. for Statements, the second example "Iterate over a copy" fails in practice.
for user, status in users.copy().items():
... if status == 'inactive': ... del users[user] ... Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'users' is not defined
active_users = {}
for user, status in users.items():
... if status == 'active': ... active_users[user] = status ... Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'users' is not defined
Hi Alex, thanks for reporting! On 5/7/20 5:47 PM, Alex Barr wrote:
NameError: name 'users' is not defined
This means the example needs a pre-defined `users` variable, you can try by defining the variable to: users = {"Hans": "active", "Andrea": "inactive", "Nils": "active"} it should work. I opened an issue to fix the documentation about this at https://bugs.python.org/issue40552 Bests, -- Julien Palard
participants (2)
-
Alex Barr
-
Julien Palard