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
https://pypi.org/project/funcoperators/

robertvandeneynde.be

Le mar. 23 avr. 2019 à 22:39, João Matos <jcrma...@gmail.com> a écrit :

> 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 ['string1', 'string2', 'string3'
> ]):
>
> For all:
> if ('string1' in master_string and 'string2' in master_string
>         and'string3' in master_string):
>
> or
>
> if all(item in master_string for item in ['string1', 'string2', 'string3'
> ]):
>
> I suggest adding some "sugar" to make it more readable by adding
> contains_any_in and contains_all_in to look like this
>
> For any:
> if master_string contains_any_in ['string1', 'string2', 'string3']:
>
> For all:
> if master_string contains_all_in ['string1', 'string2', 'string3]:
>
>
> What do you think?
>
>
> Thanks,
>
> JM
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas@python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to