[Python-ideas] a in x or in y

Carl Meyer carl at oddbird.net
Fri Feb 14 00:23:02 CET 2014


On 02/13/2014 04:04 PM, Greg Ewing wrote:
[snip]
> A syntax along the lines of
> 
>    X in either Y or Z
> 
> would avoid the problem. But we don't have a good
> candidate for 'either' that's already a keyword.

This makes me think of

    X in any(Y, Z)

which is equally concise, and I think clearer and more readable (for
garden-path reasons) than

    X in Y or in Z

It's also technically not ambiguous, since currently any() only takes
one argument, and "X in any(Y)" is useless. Still a confusing overload
of the meaning of any().

Implementation would be a bit ugly; it would need to return an object
that implements every operator magic method, and "distributes" the
operation across the objects passed to it. Equivalent could be done for
all().

Or different names could be chosen to avoid the overloads, though I'm
not sure what those names would be.

Probably there be dragons, but it might be fun to experiment with (and
doesn't require changes to the language, only new/modified builtins, or
even just library additions).

Carl


More information about the Python-ideas mailing list