Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ronaldgreeff/d530acd3f973e5767be92d6fad71155c to your computer and use it in GitHub Desktop.
Save ronaldgreeff/d530acd3f973e5767be92d6fad71155c to your computer and use it in GitHub Desktop.
# -*- 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