I have a list of strings - something like
mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text']
I want to find the first appearance of anything that starts with foobar. If I were grepping, I would look for foobar *. My current solution looks like this:
for i in mytext:
index = i.find("foobar")
if(index!=-1):
print i
Which works fine, but I wonder if there is a “better” way (like pythonic)?
Cheers, Mike
source
share