About Variables within List Comprehensions

In Python, variables defined within list comprehensions are not accessible outside of the list comprehension, so it's safe to use the same name as in the outer scope:

1
2
3
4
>>> i = "OK"
>>> l = [i for i in range(3)]
>>> print(i)
OK

Tips and Tricks Programming Python 3