Skip to content

Instantly share code, notes, and snippets.

@lega911
Created October 31, 2019 11:24
Show Gist options
  • Save lega911/74344345395ee8ea823c81b24e8579dd to your computer and use it in GitHub Desktop.
Save lega911/74344345395ee8ea823c81b24e8579dd to your computer and use it in GitHub Desktop.
words = ['abc', 'ubuntu', 'linux', 'ubuntu 16 LTS', 'redhat', 'unix', 'windows', 'macos X']
def tre(w):
w = w.lower()
r = {'__' + w[0], '_' + w[:2]}
for i in range(len(w)):
k = w[i:i+3]
while len(k) < 3:
k += '_'
r.add(k)
return r
result = []
h = tre('ubuXntu16LTS')
for w in words:
result.append((len(tre(w) & h), w))
for w in sorted(result, reverse=True):
print(w)
@lega911
Copy link
Author

lega911 commented Oct 31, 2019

(7, 'ubuntu 16 LTS')
(4, 'ubuntu')
(1, 'windows')
(1, 'unix')
(0, 'redhat')
(0, 'macos X')
(0, 'linux')
(0, 'abc')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment