stretching list comprehensions
Simon Burton
simonb at webone.com.au
Mon Aug 11 19:26:40 EDT 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?
Simon.
More information about the Python-list
mailing list