我有一个字符串列表 - 类似于以下内容:
mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text']
我想找到以foobar开头的任何内容的第一次出现。如果我在使用grep命令,那么我会搜索foobar*。我的当前解决方案如下:
for i in mytext:
index = i.find("foobar")
if(index!=-1):
print i
这样做是可以的,但我想知道有没有更好(即更符合Python风格)的方法?
谢谢, Mike