比较列表并打印

时间:2017-02-25 06:25:09

标签: python

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,如何创建它以便打印arrStar)中的字符串而不是输入中的字符串StarWars

2 个答案:

答案 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