[Python-ideas] a in x or in y

Haoyi Li haoyi.sg at gmail.com
Thu Feb 13 19:51:22 CET 2014


I think we're talking about the wrong thing by focusing on whether we want
"or in" or "or" or other finnicky syntax things. In terms of whether we can
express the logic the OP wanted, we already can:

*>>> a = {1, 2, 3}*
*>>> b = {4, 5, 6}*
*>>> c = 5*
*>>> c in a | b*
*True*

Perfectly concisely, with the exact semantics we want, e.g. when we want to
chain more things to the *|* clause, or we want to include *&* clauses, or
other things.

Maybe we want to extend *|* to other sequences which *in* works on. Maybe
we could make *|* chaining on non-sets lazy so we don't build unnecessary
data structures. Maybe we want to add a fast-path in the interpreter to
speed up this special case. Maybe we want to overload *or* on sets and seqs
to behave similarly to how *|* does.

On the other hand, I think introducing new syntax for something *that
already works with almost the same syntax and exactly the desired
semantics* would
be a terrible idea.

On Thu, Feb 13, 2014 at 10:34 AM, MRAB <python at mrabarnett.plus.com> wrote:

> On 2014-02-13 17:04, אלעזר wrote:
> > Another issue: people will expect
> >     for i in a and not in b:
> >         print(i)
> > to work.
>
> Do they currently expect:
>
>     for i in a and i not in b:
>         print(i)
>
> to work?
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140213/5314d852/attachment.html>


More information about the Python-ideas mailing list