大家好,我有多个带有字符串的列表。铁:
params = {
"str1":"A Teststring which tests.",
"str2":"Strings are awesome to test",
"str3":"Teststring is a string that tests ",
"str4":"String awesome test tests"
}
erg =[]
allstrings = ['str1','str2','str3','str4']
userkeywords = ['teststring','awesome','test','string']
for str in allstrings:
strkeywords = params[str].split()
common = list(set(userkeywords) & set(strkeywords) )
howmuch = len(common)
erg.append(howmuch)
print erg
使用此代码,我得到参数字符串中有多少单词是相同的。但是我怎样才能打印出与用户关键字有最多共同词的字符串。
期待:
str1 : 4
str2: 3
str4: 3
(数字是例子)
任何人都可以帮忙吗?