[Python-ideas] Accessing the result of comprehension's expression from the conditional
g.brandl at gmx.net
Sat Jun 20 22:00:42 CEST 2009
Lie Ryan schrieb:
> Terry Reedy wrote:
>> Steven D'Aprano wrote:
>>> On Sat, 20 Jun 2009 08:31:26 am Lie Ryan wrote:
>>> You don't like lambda? Fine, define an external function first. Then
>>> you can write:
>>> filter(pred, (f(x) for x in seq))
>>> There's no violation of DRY, there's no redundancy, there's no lambda,
>>> there's no "y" variable needed. What's ugly about it?
>> I think its great and that it kills any justification for the proposal.
> I hate it. It mixes map/filter style and comprehension style; and the
> fact it does so in a single line only makes it worse. Not that it would
> be any better in two lines.
Taking this further, using only map/filter style like this
filter(pred, map(f, seq))
takes two steps. Why is it so bad that doing it in a listcomp
(el for el in (f(y) for y in seq) if el > 2)
takes two steps as well?
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.
More information about the Python-ideas