Guest User

Untitled

a guest
Jan 17th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from difflib import SequenceMatcher
  3.  
  4. def f1(string_list):
  5. d = {}
  6. for s in string_list:
  7. d[s] = score(s, string_list)
  8. return d
  9.  
  10. def score(string, string_list):
  11. x = [i for i in [SequenceMatcher(None, string, s).ratio() for s in string_list if not s == string] if i > 0]
  12. return max(x)+min(x)-(sum(x)/len(x))
  13.  
  14. string_list = ['abcde', 'abcde fg', 'abc', 'fg', 'abcfg', ' ']
  15. r = f1(string_list)
Add Comment
Please, Sign In to add comment