list comprehension question

Emile van Sebille emile at fenx.com
Fri May 1 13:36:25 EDT 2009


On 5/1/2009 9:19 AM Arnaud Delobelle said...
> Emile van Sebille <emile at fenx.com> writes:
>> On 5/1/2009 7:31 AM J Kenneth King said...
>>> I love comprehensions, but abusing them can lead to really dense and
>>> difficult to read code.
>> I disagree on dense and difficult, although I'll leave open the
>> question of abuse.
>>
>> b = [ item for pair in a for item in pair ]
>>
>> This is exactly the code above expressed in comprehension form.
> 
> If the comprehension above is an abuse, then every nested list
> comprehension is an abuse of comprehensions so they might as well not be
> in the language...
> 

I hope you didn't understand me to say that this usage is abuse.  That's 
certainly not what I mean.  I have, however, examples in my code base 
that _would_ qualify as abuse (mostly from pre dictionary comprehension 
vintage where I would build a dict from within a list comp), and I have 
seen enough from this group to know that abuse abounds, with only slight 
provocation.  :)

Fondly-remembering-byte-code-hacks-and-introspection-ly y'rs,

Emile




More information about the Python-list mailing list