I was trying to otpimze a code that returns the length of the Longest Common Substring between two strings and realized that the insersection function returns pretty much the same. Am I correct?
a = input()
b = input()
print (len(set(a).intersection(b)))
No, because the intersection of your words will break the individual letters into elements of a list. For example,
a = 'abcd'
b = 'dcba'
becomes
a = ['a', 'b', 'c', 'd']
b = ['d', 'c', 'b', 'a']
The length of the intersection will be 4, but that is not correct for your case since 'abcd' and 'dcba' have no common substring longer than length 1.
Also, using set on a word will remove any duplicate letters in your word, which will also mess up searching for common substrings.
What you would need to do instead is something like split the two words into lists all possible substrings, like what is done in this post. Then you can do an intersection of those lists and take the element of greatest length.