我想编写一个在两个文本之间进行比较的代码,并告诉我一些相同的字符(或某些相同的单词),我该怎么做?我不想使用:
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(' ')))
感谢这个答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句