[Python-ideas] contains_any_in and contains_all_in
João Matos
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
mentioned.
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']):
>
> 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... at python.org <javascript:>
> 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/1b29bf98/attachment.html>
More information about the Python-ideas
mailing list