list comprehension question

Arnaud Delobelle arnodel at googlemail.com
Fri May 1 12:19:21 EDT 2009


Emile van Sebille <emile at fenx.com> writes:

> On 5/1/2009 7:31 AM J Kenneth King said...
>> Chris Rebert <clp2 at rebertia.com> writes:
>>> b = []
>>> for pair in a:
>>>     for item in pair:
>>>         b.append(item)
>>
>> This is much more clear than a nested comprehension.
>>
>> 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...

-- 
Arnaud



More information about the Python-list mailing list