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!

Pritish Mishra
  • 424
  • 5
  • 13

1 Answers1

2

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']
U12-Forward
  • 65,118
  • 12
  • 70
  • 89