我有一个大字符串和一个搜索字符串列表,想要构建一个布尔列表,指示每个搜索字符串是否存在于大字符串中。在Python中,最快的方法是什么?
以下是使用单纯方法的玩具示例,但我认为可能有更有效的方法。
例如,下面的示例应返回[1, 1, 0],因为"hello"和"world"都存在于测试字符串中。
以下是使用单纯方法的玩具示例,但我认为可能有更有效的方法。
例如,下面的示例应返回[1, 1, 0],因为"hello"和"world"都存在于测试字符串中。
def check_strings(search_list, input):
output = []
for s in search_list:
if input.find(s) > -1:
output.append(1)
else:
output.append(0)
return output
search_strings = ["hello", "world", "goodbye"]
test_string = "hello world"
print(check_strings(search_strings, test_string))