找出两个字符串中出现的单词数
Find the number of words that occur in both strings
我想写一个代码来比较两个文本并告诉我一些相同的字符(或一些相同的词)
我怎样才能做到这一点?
我不想使用:
print(text1 == text2)
我除了:
a = "i from israel"
b = "hello i from london"
# *i* and *from* are in both strings = 2
c = "apple orange banana watermelon"
d = "apple is very healthy, also banana and orange"
# *apple* and *banana* and *orange* are in both strings = 3
我想比较低恶化我的意思是,计算两个字符串中的单词。
谢谢
你可以通过这样做得到相同的单词:list(set(a.split(' ')) & set(b.split(' ')))
感谢this回答。
我想写一个代码来比较两个文本并告诉我一些相同的字符(或一些相同的词) 我怎样才能做到这一点? 我不想使用:
print(text1 == text2)
我除了:
a = "i from israel"
b = "hello i from london"
# *i* and *from* are in both strings = 2
c = "apple orange banana watermelon"
d = "apple is very healthy, also banana and orange"
# *apple* and *banana* and *orange* are in both strings = 3
我想比较低恶化我的意思是,计算两个字符串中的单词。 谢谢
你可以通过这样做得到相同的单词:list(set(a.split(' ')) & set(b.split(' ')))
感谢this回答。