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

Devin Jeanpierre jeanpierreda at gmail.com
Mon Jan 16 15:47:39 CET 2012

On Mon, Jan 16, 2012 at 9:15 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> And, since we *know* anything even vaguely resembling an embedded
> assignment syntax would almost immediately be adopted for any-and-all
> of the various embedded assignment requests we've seen over the years,
> here's how it would look for the regex use case:
>    if some m in [pattern.search(data)] if m is not None:
>        ...
> Hmm, still doesn't feel right to me - trying to shove a square peg
> (mathematical quantification) into a round hole (Python's syntax). In
> particular, the any()/all() way of doing things avoids the double-if
> problem when used in an if statement, whereas the version that
> captures the variable (and hence moves the predicate to the end) reads
> very strangely in that case.

You can always add a full-on assignment-as-expression, if you're
concerned about that.

    if (m := pat.search(data)) is not None:

Also, the keyword doesn't have to be "if". I've always read the bar as
"such that" or "where".

-- Devin

More information about the Python-ideas mailing list