def words_in_both(string1, string2):
s = set()
res = []
for word in string1.lower().split():
if word not in s: s.add(word)
for word in string2.lower().split():
if word in s: res.append(word)
return res
print(words_in_both("Here is my MY test1","Here IS My MY mY test2"))
我在代码中遇到错误,我试图只返回两个字符串中的单词,而不考虑大小写,但是当我运行代码时,我返回的是:['here'、'is'、'my'、'my'、'my']
有人能帮我找出我的问题吗?