Created
January 16, 2019 22:12
-
-
Save ronaldgreeff/d530acd3f973e5767be92d6fad71155c 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
# -*- coding: utf-8 -*- | |
from difflib import SequenceMatcher | |
def f1(string_list): | |
d = {} | |
for s in string_list: | |
d[s] = score(s, string_list) | |
return d | |
def score(string, string_list): | |
x = [i for i in [SequenceMatcher(None, string, s).ratio() for s in string_list if not s == string] if i > 0] | |
return max(x)+min(x)-(sum(x)/len(x)) | |
string_list = ['abcde', 'abcde fg', 'abc', 'fg', 'abcfg', ' '] | |
r = f1(string_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment