同じコードのチャンクを繰り返し書いていることに気づきました。
def stringInList(str, list):
retVal = False
for item in list:
if str in item:
retVal = True
return retVal
この関数をより速く/より少ないコードで書く方法はありますか? 私は通常、次のように if ステートメントでこれを使用します。
if stringInList(str, list):
print 'string was found!'