Created
October 31, 2019 11:24
-
-
Save lega911/74344345395ee8ea823c81b24e8579dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Author
lega911
commented
Oct 31, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment