[Python-ideas] a in x or in y

Haoyi Li haoyi.sg at gmail.com
Thu Feb 13 20:57:25 CET 2014


> "somestring" in "wholesome" or in "string of words"
>
> is not the same as concatenating the two strings and checking if the
> target string is in the result.

That's true, but I strongly suspect we can get what we want via plain old

*"somestring" in "wholesome" | "string of words"*

syntax by overloading the *|* operator to return some data structure that
does what we want with *in*.

In general, I feel like implementing cool stuff as libraries is superior to
implementing cool stuff as hardcoded semantics in the interpreter. This
seems like a case where implementing the semantics we want via *|* seems
not just feasible, but trivial.


On Thu, Feb 13, 2014 at 11:35 AM, Chris Angelico <rosuav at gmail.com> wrote:

> On Fri, Feb 14, 2014 at 5:51 AM, Haoyi Li <haoyi.sg at gmail.com> wrote:
> > 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
> >
> > ...
> > Maybe we want to extend | to other sequences which in works on.
>
> Most definitely. The 'in' operator is far broader than the set() type.
> Notably:
>
> "somestring" in "wholesome" or in "string of words"
>
> is not the same as concatenating the two strings and checking if the
> target string is in the result.
>
> ChrisA
> _______________________________________________
> 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/7f68a1ae/attachment-0001.html>


More information about the Python-ideas mailing list