The objective of the proposal is to increase readability.
IMO using re is even more unreadable than the and/or or any/all I mentioned.
quarta-feira, 24 de Abril de 2019 às 05:47:04 UTC+1, Robert Vanden Eynde
escreveu:
>
> Trivial with re module, which will answer thequestion in one pass.
>>
>
>
The objective of the proposal is to increase readability.
IMO your options are even more unreadable than the and/or or any/all I
mentioned.
quarta-feira, 24 de Abril de 2019 às 05:33:12 UTC+1, Terry Reedy escreveu:
>
> On 4/23/2019 4:39 PM, João Matos wrote:
> > Hello,
> >
> > If we want to
On 23/04/2019 21:39, João Matos wrote:
If we want to check if a string contains any/all of several other strings
we have to use several or/and conditions or any/all.
[snip]
I suggest adding some "sugar" to make it more readable by adding
contains_any_in and contains_all_in to look like this
>
> Trivial with re module, which will answer thequestion in one pass.
>
re.search('|'.join(map(re.escape, ['string1', 'string2', 'string3'])),
master_string)
For those who might find it non trivial.
___
Python-ideas mailing list
On 4/23/2019 4:39 PM, João Matos wrote:
Hello,
If we want to check if a string contains any/all of several other
strings we have to use several or/and conditions or any/all.
For any:
|if ('string1' in master_string or 'string2' in master_string
or 'string3' in master_string):
or
Here comes funcoperators again :
if master_string -contains_any_in- ['string1', 'string2', 'string3']:
Given
from funcoperators import infix
@infix
def contains_any_in(string, iterable):
return any(item in string for item in iterable)
pip install funcoperators
Hello,
If we want to check if a string contains any/all of several other strings
we have to use several or/and conditions or any/all.
For any:
if ('string1' in master_string or 'string2' in master_string
or 'string3' in master_string):
or
if any(item in master_string for item in