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
ifany(item inmaster_string foritem in['string1','string2','string3']):

Trivial with re module, which will answer the question in one pass.


For all:
|
||if ('string1' in master_string and 'string2' in master_string
         and'string3' in master_string):
or
||ifall(item inmaster_string foritem in['string1','string2','string3']):

Tougher.
Are the strings guaranteed to not be prefixes of each other?
Do you want to allow overlaps?
Can do in one pass by compiling a new re every time an item is found.
If overlaps not wanted, re.iterfind will find all occurrence of any, so feed to set and see if all found.

--
Terry Jan Reedy


_______________________________________________
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