[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-29 Thread Soni L.
would rather it took List[str] patterns instead, for matching against
List[str] input. so you could do things like:

pattern = ["foo", "?", "\", "?", "bar", "baz"]
input = ["foo", "?", "bar", "baz"] # matches
input = ["?", "bar", "baz"] # matches
input = ["foo?barbaz"] # doesn't match

bonus points if it also takes arbitrary objects:

pattern = [None, True, False, "?"]
input = [None, True] # matches
input = [None, False] # doesn't match
input = [None, True, False] #matches

On 2020-09-28 8:10 p.m., Giang Le wrote:
> Hi Everyone,
>
> I would like to propose an idea for the regular expression module 
> re.search(Pattern, Input) to support List[str] input type.
> So it will return a matched object list if the input is a string list. 
> Otherwise, it will return a normal matched object, if the input is a normal 
> string
>
> Best Regards
> Giang
> ___
> Python-ideas mailing list -- python-ideas@python.org
> To unsubscribe send an email to python-ideas-le...@python.org
> https://mail.python.org/mailman3/lists/python-ideas.python.org/
> Message archived at 
> https://mail.python.org/archives/list/python-ideas@python.org/message/4LOOP2FDK7JQ7XU3Z4Y7JNLOOW5FQOHH/
> Code of Conduct: http://python.org/psf/codeofconduct/
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QI2QWN7PO7D5JXQ4VPITDTUWCX7SIVZ2/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-29 Thread Oleg Broytman
import re
re_search = re.search

def re_search_list(pattern, list_or_text):
if isinstance(list_or_text, str):
return re_search(pattern, list_or_text)
return [re_search_list(pattern, i) for i in list_or_text]

re.search = re_search_list

Bottom line: no need to change the function, you can do it yourself.

On Tue, Sep 29, 2020 at 06:19:29AM -, Giang Le  
wrote:
> Hi, I would like to have the same function re.search(pattern, input) to keep 
> main code structure to be the same. The input into the re.search function 
> will be depended on other previous functions. It is also more dynamic for 
> users. Thank you.

Oleg.
-- 
Oleg Broytmanhttps://phdru.name/p...@phdru.name
   Programmers don't die, they just GOSUB without RETURN.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/2ZO7GNTT567EQC3DQD6MEVI62WYMK6X2/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-29 Thread Giang Le
Hi, I would like to have the same function re.search(pattern, input) to keep 
main code structure to be the same. The input into the re.search function will 
be depended on other previous functions. It is also more dynamic for users. 
Thank you.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/ALKQ7754NLPDFYK6F743YFCYJD5THHOE/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-29 Thread Marco Sulla
On Tue, 29 Sep 2020 at 04:39, <2qdxy4rzwzuui...@potatochowder.com> wrote:
>
> On 2020-09-28 at 23:10:24 -,
> Giang Le  wrote:
>
> > I would like to propose an idea for the regular expression module
> > re.search(Pattern, Input) to support List[str] input type.
>
> > So it will return a matched object list if the input is a string
> > list. Otherwise, it will return a normal matched object, if the input
> > is a normal string
>
> How would that change be better than a new function:
>
> def regex_search_list(regex, pattern, list_of_inputs):
> [regex.search(pattern, input) for input in list_of_inputs]
>
> (or possibly an equivalent method of regexen)?

I suppose that another advantage is that the list is passed to C, so
it's faster.
Not sure such an overloading is desirable.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/LDYHQEKW776JISFA6FNBGETVUCUW2KQT/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread Giang Hoang Le
Hi, I would like to have the same function re.search(pattern, input) to
keep main code structure to be the same. The input into the re.search
function will be depended on other previous functions. It is also more
dynamic for users. Thank you.
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SMBNFYXY3DGLQ6SHIRDQSEAYFE654DU3/
Code of Conduct: http://python.org/psf/codeofconduct/


[Python-ideas] Re: Regular Expression | re - Support String List Input Type List[str]

2020-09-28 Thread 2QdxY4RzWzUUiLuE
On 2020-09-28 at 23:10:24 -,
Giang Le  wrote:

> I would like to propose an idea for the regular expression module
> re.search(Pattern, Input) to support List[str] input type.

> So it will return a matched object list if the input is a string
> list. Otherwise, it will return a normal matched object, if the input
> is a normal string

How would that change be better than a new function:

def regex_search_list(regex, pattern, list_of_inputs):
[regex.search(pattern, input) for input in list_of_inputs]

(or possibly an equivalent method of regexen)?
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/QSOAHKIKTJMYEWT24L6NTYIXSFLPT5LP/
Code of Conduct: http://python.org/psf/codeofconduct/