我想写一段代码,在两个文本之间进行比较,告诉我一些相同的字符(或一些相同的单词),我该怎么做呢?我不想使用:
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我想与低加重进行比较,我的意思是,计算两个字符串中的单词。谢谢
发布于 2020-01-29 00:38:12
您可以通过执行以下操作获得相同的单词:list(set(a.split(' ')) & set(b.split(' ')))
感谢this answer。
https://stackoverflow.com/questions/59937637
复制相似问题