stretching list comprehensions

Simon Burton simonb at webone.com.au
Mon Aug 11 20:04:30 EDT 2003


On Mon, 11 Aug 2003 16:44:52 -0700, David Eppstein wrote:

> In article <pan.2003.08.11.23.26.39.60449 at webone.com.au>,
>  Simon Burton <simonb at webone.com.au> wrote:
> 
>> >>> 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?
>> 
> 
> It does work with the loops in the opposite order:
> 

Aha! 

It seems the wrong order to my "innermost first" mind. Guess i'm changing
that now.

Thanks,

Simon.





More information about the Python-list mailing list