[Chicago] Nested List Comprehension in PyDev

Oren Livne livne at uchicago.edu
Tue Oct 16 04:45:03 CEST 2012


That's a great analysis. It worked as you predicted. Thank you so much, JM!
Oren

On 10/15/2012 9:14 PM, JongMan Koo wrote:
>> In [136]: [(k, x) for x in d[k] for k in d]
> This is actually equivalent to:
>
> ret = []
> for x in d[k]:
>    for k in d:
>       ret.append((k, x))
>
> so the undefined exception for k is actually legit. I would guess it
> was working in IPython because you already had k in your scope. You
> should change it to:
>
>> In [136]: [(k, x) for k in d for x in d[k]]
> for the intended behavior.
>
> Cheers,
> JM
>
>
> 2012/10/15 Oren Livne <livne at uchicago.edu>:
>> Dear All,
>>
>> If I type this in ipython, I get
>> In [135]: d = {1: [2,3], 2: [4,5]}
>>
>> In [136]: [(k, x) for x in d[k] for k in d]
>> Out[136]: [(1, 4), (2, 4), (1, 5), (2, 5)]
>>
>> The second command in Eclipse PyDev (using the same python installation)
>> says "Undefined variable: k" for the k in the string "d[k]".
>>
>> What's wrong with PyDev?
>> Thanks,
>> Oren
>>
>> _______________________________________________
>> Chicago mailing list
>> Chicago at python.org
>> http://mail.python.org/mailman/listinfo/chicago
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> http://mail.python.org/mailman/listinfo/chicago


-- 
A person is just about as big as the things that make him angry.



More information about the Chicago mailing list