stretching list comprehensions
simonb at webone.com.au
Tue Aug 12 01:26:40 CEST 2003
I was quite delighted when i found this:
>>> nums = [ x+y for x in range(10) for y in range(10) ]
Great! No more list of list joining shenanigans...
Shortly thereafter, i tried this:
>>> del y
>>> nums = [ x+y for x in range(y) for y in range(10) ]
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'y' is not defined
Well.. Is there an inherent reason why this could/should not be made to work?
More information about the Python-list