daily pastebin goal
72%
SHARE
TWEET

Untitled

a guest Jan 17th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top