[Python-ideas] Fwd: quantifications, and tuple patterns

Paul Moore p.f.moore at gmail.com
Sat Jan 14 13:32:05 CET 2012

Sorry, should have replied on list.

On 14 January 2012 05:25, Annie Liu <liu at cs.stonybrook.edu> wrote:
> For example, even the simplest "some x in s has pred", when a witness
> for x is not needed, could end up like "{x for x in s if pred}",
> "any(pred for x in s)", "len(...)!=0", "len...>0", len...>=1", ... not
> to mention the many more kinds of loops and tests written by the
> majority of students not used to writing queries/comprehensions.  Even
> more kinds of loops and bigger hassles are involved when a witness for
> x is needed.

I'm confused as to why any(pred for x in s) is unacceptable here?

> For another example, a simple "each x in s has x > y" tends to end up
> like "min(s)>y", which is incorrect, since s could be empty, so one
> has to either add this condition or invent some boundary value for
> min, which is error-prone since it is sensitive to the possible values
> of elements of s and the uses of these values.

all(x > y for x in s) seems to me both idiomatic and correct.

I'm not sure quite what you're proposing here - it seems like you're
asking for new syntax to do the same job as any and all, which already
do exactly what's needed. New syntax has to provide something much,
much better if it's likely to be accepted.

Please explain more clearly.

More information about the Python-ideas mailing list