s1_len, s2_len = len(s1), len(s2)
maxlen = max(s1_len, s2_len)
first, second = (s2, s1) if s1_len == maxlen else (s1, s2)
ft_1 = set() // all related words with first sentence
for x in first:
ft_1.add(x)
n, _ = nearby(x)
for o in n[:5]:
ft_1.add(o)
ft_2 = set() // all related words with second sentence
for x in second:
ft_2.add(x)
n, _ = nearby(x)
After Change
s1_len, s2_len = len(s1), len(s2)
maxlen = s1_len
if s1_len == s2_len:
first, second = sorted([s1, s2])
elif s1_len < s2_len:
first = s1
second = s2
maxlen = s2_len