[Python-ideas] contains_any_in and contains_all_in
Robert Vanden Eynde
robertve92 at gmail.com
Tue Apr 23 20:50:05 EDT 2019
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 <jcrmatos at 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 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/20190424/cb44a85f/attachment-0001.html>
More information about the Python-ideas
mailing list