1

I am trying to find if two strings has same set of words for example if we have two strings like this,

a = "Linear Regression is a algorithm in ML"
b = "Linear Regression is a supervised learning algo"

I want my algorithm to find same set of words so I expect it to output "Linear Regression" as it comes in both the strings

I have tried this :

a = "Linear Regression is a algorithm in ML"
b = "Linear Regression in a supervised learning algo"

if a in b:
    print(True)

else:
    print(False)

It is returning False

That's why I want a algorithm which can do it efficiently and quickly.

Thanks!

1 Answers1

1

You could try this list comprehension with str.split:

print([i for i in a.split() if i in b.split()])

Output:

['Linear', 'Regression', 'is', 'a']
U13-Forward
  • 69,221
  • 14
  • 89
  • 114