O'Reilly logo
  • Brandon Reeser thinks this is interesting:

The sorted results are correct, but the found result is wrong. Items from group were definitely found in numbers, but the function returned False. How could this happen?

When you reference a variable in an expression, the Python interpreter will traverse the scope to resolve the reference in this order:

1. The current function’s scope

2. Any enclosing scopes (like other containing functions)

3. The scope of the module that contains the code (also called the global scope)

From

Cover of Effective Python: 59 Specific Ways to Write Better Python

Note

hghfjhgjh