I'm trying to check intersection between two strings using Python. I defined this function:
def check(s1,s2):
word_array = set.intersection(set(s1.split(" ")), set(s2.split(" ")))
n_of_words = len(word_array)
return n_of_words
It works with some sample string, but in this specific case:
d_word = "BANGKOKThailand"
nlp_word = "Despite Concerns BANGKOK"
print(check(d_word,nlp_word))
I got 0. What am I missing?
sum(word in s1 for word in s2.split(" ")), doing substring tests. That could perhaps lead to false positives if things likethematch words likethese, but that's probably impossible to avoid if you want your code to match the example strings you've given.