Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- 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)
Add Comment
Please, Sign In to add comment