我有一个字符串列表 - 类似于
mytext = ['This is some text','this is yet more text','This is text that contains the substring foobar123','yet more text']
我想找到以 foobar 开头的任何内容的第一次出现。如果我是 grepping,那么我会搜索 foobar*。我目前的解决方案看起来像这样
for i in mytext:
index = i.find("foobar")
if(index!=-1):
print i
哪个工作得很好,但我想知道是否有一种“更好”(即更pythonic)的方式来做到这一点?
干杯,迈克