短い文字列の長いリストがあり、(通常は)長いテキスト文字列でこれらすべての項目を検索したいと思います。私のリストの長さは約500の短い文字列であり、Pythonを使用して約10,000文字の長さのソーステキストで発生するすべてのものを検索したいと思います。
これが私の問題の短い例です:
cleanText = "four score and seven years ago our fathers brought forth on this continent a new nation conceived in Liberty and dedicated to the proposition that all men are created equal"
searchList = ["years ago","dedicated to","civil war","brought forth"]
cleanTextで発生するsearchList内のアイテムを検索するための現在の方法は次のとおりです。
found = [phrase for phrase in searchList if phrase in cleanText]
これはPythonで最速の方法ですか?正確に遅いわけではありませんが、規模(searchList内の500アイテムと10,000文字のcleanText)では、私が望むよりも少し遅いようです。