[Python-ideas] contains_any_in and contains_all_in

Terry Reedy tjreedy at udel.edu
Wed Apr 24 15:27:19 EDT 2019


On 4/24/2019 12:50 PM, João Matos wrote:
> The objective of the proposal is to increase readability.

Relational expressions are powerful and flexible and yes, people find 
them hard to read until they really learn the sublanguage.  The solution 
is to isolate application-specific regexes in functions that you then 
use in the application.

 > IMO using re is even more unreadable than the and/or or any/all
 > I mentioned.

Your multiple scan str-method solutions can also be wrapped if they are 
sufficient for an application.

The stdlib provides basic building blocks.  If we endlessly add simple 
functions to the stdlib, it will become harder and harder to learn.

> quarta-feira, 24 de Abril de 2019 às 05:47:04 UTC+1, Robert Vanden Eynde 
> escreveu:

>     [Me] Trivial with re module, which will answer the question in one pass.
> 
>     For those who might find it non trivial.

>     re.search('|'.join(map(re.escape, ['string1', 'string2',
>     'string3'])), master_string)

This should be wrapped in an application-specific function, with 
whatever name and parameters one prefers.

If this particular re example is not in Regular Expression HOWTO, it 
could be added.  It is easy to forget the need to apply re.escape to 
general, non-identifier strings.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list