>
> 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
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
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
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
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
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
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
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
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
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
10 matches
Mail list logo