It's not a mistake.
The for loop does not create a new scope. Only functions and modules introduce a new scope with classes, list / dict / set * lambdas views, and generators are specialized functions when it comes to defining a scope.
This is confirmed by the for documentation :
The goal list is not deleted when the cycle is completed, but if the sequence is empty, it will not be assigned at all by the cycle.
Practical use of this function is getting the last element of iterable :
last = defaultvalue for last in my_iter: pass
* List enumerations in Python 2 work like for loops, a new scope, but in Python 3 they, as well as dict and set understanding in versions of Python, create a new scope.
source share