arr = ["mincraft", "Star"]
inputs = ["minecraft?s update", "StarWars", "Babe"]
i = 0
while i != len(inputs):
if any(words in inputs[i] for words in arr):
print inputs[i];
i += 1
此代码输出Starwars
,如何创建它以便打印arr
(Star
)中的字符串而不是输入中的字符串StarWars
)
答案 0 :(得分:4)
你可以这样做:
temp = [i for i in arr for j in inputs if i in j]
输出:
['Star']
答案 1 :(得分:3)
public function addData($id, $name, $address, $fee){
}
输出:arr = ["mincraft","Star"]
inputs = ["minecraft?s update","StarWars","Babe"]
for item in arr:
if len([x for x in inputs if item in x]) > 0: print item