
Le Fri, 19 Jun 2009 09:45:08 -0400, Jim Jewett <jimjjewett@gmail.com> s'exprima ainsi:
On Fri, Jun 19, 2009 at 7:34 AM, Tal Einat<taleinat@gmail.com> wrote:
Just using [f(x) for x in nums if f(x) > 0] is the most readable and obvious option.
I would often prefer to break it into two steps:
temp = (f(x) for x in nums) results = [e for e in temp if e>0]
Others will dislike the extra line and temp var, which is one reason it isn't among the several solutions previously suggested. Are these differences big enough (or the solutions obscure enough) that the variation is itself a cost of the current situation?
Ditto for me. A list comp with both computation and filtering is for me two ideas, two steps, so I write two lines anyway. This also has the advantage to disambiguate the order issue (computation or filter first?) and there is no risk of double side-effect (which anyway I never use, but who knows...). Denis ------ la vita e estrany