I can understand current way is little redundancy. But making new Keyword OR,
AND or something like that is not kind to beginners.
I don't think this proposal follows the zen of Python.
However, I think what you want to say is nice.
So, I propose this way.
if (1, 2, 3) or in [1, 4, 5]:
code
if {"1", "2", "3"} and in "2020":
code
I don't think this is perfect suggestion. But I'm happy if I can write in
this(or something like this) way.
And to ChrisA.
If one of the elements were instance of list(or unhashable type), that won't
work.
like below.
class OR:
def __init__(self, *args):
self.data = args
def in_(self, other):
return any((x in other for x in self.data))
print({[1], [2], [3]} & [[1], [3]]) # invalid
print(OR([1], [2], [3]).in_([[1], [3]])) # valid
thank you.
2019/12/31 15:20、[email protected]のメール:
> Hi
> I think the following syntax's:
>
> if foo in foobar or bar in foobar or baz in foobar:
> pass
> if foo in foobar and bar in foobar and baz in foobar:
> pass
>
> can be more readable and shorter if written as:
>
> if foo or bar or baz in foobar:
> pass
> if foo and bar and baz in foobar:
> pass
>
> maybe for "is" instead of:
>
> if foobar is foo or foobar is bar or foobar is baz:
> pass
>
> if foobar is foo or bar or baz:
> pass
>
> now the recommended syntax translate to this: (I think so)
>
> if foo (IS NOT '0' or None or empty) or bar (IS NOT '0' or None or empty) or
> baz in foobar
>
> so probably we must introduce a new type of 'or' (I recommend the CAPITAL
> "OR","AND") so this:
>
> if foo OR bar OR baz in foobar:
> pass
>
> translates to this:
>
> if foo in foobar or bar in foobar or baz in foobar:
> pass
> _______________________________________________
> Python-ideas mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at
> https://mail.python.org/archives/list/[email protected]/message/5UY57M2LZR4XMMOC7CIJ6HFXYXSICAIU/
> Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/BHR6X4LGK2NIC4KB2WZ45W5FIYG2IUZG/
Code of Conduct: http://python.org/psf/codeofconduct/