Re: [Python-ideas] contains_any_in and contains_all_in

2019-04-23 Thread Robert Vanden Eynde
> > Trivial with re module, which will answer thequestion in one pass. > re.search('|'.join(map(re.escape, ['string1', 'string2', 'string3'])), master_string) For those who might find it non trivial. ___ Python-ideas mailing list Python-ideas@python.org

Re: [Python-ideas] contains_any_in and contains_all_in

2019-04-23 Thread Terry Reedy
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 ifan

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-23 Thread 林自均
Hi all, Thanks for the explanation. Now I agree that the need for list.rindex() is not as common as str.rindex(). In fact, I only need list.rindex() when doing some algorithm problems. I guess that doesn't count as real need here. Best, John Lin Guido van Rossum 於 2019年4月24日 週三 上午4:20寫道: > On

Re: [Python-ideas] contains_any_in and contains_all_in

2019-04-23 Thread Robert Vanden Eynde
Here comes funcoperators again : if master_string -contains_any_in- ['string1', 'string2', 'string3']: Given from funcoperators import infix @infix def contains_any_in(string, iterable): return any(item in string for item in iterable) pip install funcoperators https://pypi.org/project/funco

[Python-ideas] contains_any_in and contains_all_in

2019-04-23 Thread João Matos
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 if any(item in master_string for item in ['str

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-23 Thread Guido van Rossum
On Tue, Apr 23, 2019 at 1:02 PM MRAB wrote: > On 2019-04-23 18:52, Terry Reedy wrote: > > On 4/23/2019 2:44 AM, 林自均 wrote: > >> Hi all, > >> > >> I found that there are str.index() and str.rindex(), but there is only > >> list.index() and no list.rindex(). > > > > str.index and list.index are rel

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-23 Thread MRAB
On 2019-04-23 18:52, Terry Reedy wrote: On 4/23/2019 2:44 AM, 林自均 wrote: Hi all, I found that there are str.index() and str.rindex(), but there is only list.index() and no list.rindex(). str.index and list.index are related but not the same. The consistency argument is better applied to fin

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-23 Thread Terry Reedy
On 4/23/2019 2:44 AM, 林自均 wrote: Hi all, I found that there are str.index() and str.rindex(), but there is only list.index() and no list.rindex(). str.index and list.index are related but not the same. The consistency argument is better applied to find-rfind, index-rindex, partition-rparti

Re: [Python-ideas] What are the strong use cases for str.rindex()? (John Lin)

2019-04-23 Thread Thautwarm Zhao
IMO, there're lots of use cases in parsing related stuffs, which requires rindex a lot, say, when you have generated a tokenizer which might across multiple lines: line 8: X """ line 9: line 10: """ In this case, we need to extract 2 tokens X and , a multiline whitespace string. After getting

Re: [Python-ideas] What are the strong use cases for str.rindex()?

2019-04-23 Thread Brett Cannon
Given "abcdefabcdefabcdef", what is the last result of "abc"? x.rindex("abc") will tell you. Given [1, 2, 3, 4, 5, 1, 2, 3, 4, 5] where is the last result of 3? reversed(x).index(3) will tell you (or x[::-1]). Notice how with lists you can easily reverse them and still get at the value since you