[Python-ideas] contains_any_in and contains_all_in
jcrmatos at gmail.com
Wed Apr 24 12:50:10 EDT 2019
The objective of the proposal is to increase readability.
IMO your options are even more unreadable than the and/or or any/all I
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 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']):
> 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
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas