[Python-ideas] Introducing where clauses

Andrey Popp 8mayday at gmail.com
Mon Jun 22 15:16:35 CEST 2009


On Mon, Jun 22, 2009 at 4:59 PM, Jim Jewett<jimjjewett at gmail.com> wrote:
> On Mon, Jun 22, 2009 at 8:46 AM, Andrey Popp<8mayday at gmail.com> wrote:
>>    [(y, y) for x in some_iterable if y < 2 where y = f(x)]
>>
>> looks more naturally than three suggested variants.
>
> Only if you are already thinking about SQL.
>
> An "as" would be almost as good as a "where", and would better match
> the way python has evolved so far.

I thinking mostly about Haskell. "as" or "where"- for me, there is no
difference.

> But that still doesn't answer the real question.  In isolation, I
> would see either as a real (if perhaps small and isolated) improvement
> to readability.
>
> The catch is that the improvement must be dramatic enough to justify
> the cost -- which is extra complexity to the language as a whole.
> That isn't a cost you see as easily, because you're thinking about
> comprehensions; it is instead a small tax paid by people doing regular
> function calls and if branching and for loops.  It isn't a big tax,
> but it is cumulative, and python has worked hard to minimize it.

I am not about list comprehension only, there are other cases for
where-clause, for example lambdas:

    f = lambda x: (x, y) if x > 0 else (x, 0) where y = g(x)

Or maybe more. List comprehension are only small example, that is show
the one of use-cases for where-clause.



More information about the Python-ideas mailing list