[Python-ideas] contains_any_in and contains_all_in

João Matos jcrmatos at gmail.com
Tue Apr 23 16:39:05 EDT 2019


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190423/62142fab/attachment.html>


More information about the Python-ideas mailing list