mad_alien

Strike_A_Match Python algorithm

Sep 28th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. def Splitdigrams (a="hello world"):
  2.     b=a.upper().split()
  3.     c=[]
  4.     for i in b:
  5.         if len(i)<=2:
  6.             c.append(i)
  7.         else:
  8.             c.extend([i[x:x+2] for x in range(len(i)-1)])
  9.     return c
  10.  
  11. def strike_a_match(str1=u"ΓΕΡΩΝ ΠΑΙΣΙΟΣ", str2=u"ΓΕΡΩΝ ΠΑΣΤΙΤΣΙΟΣ"):
  12.     digrams1=Splitdigrams(str1)
  13.     digrams2=Splitdigrams(str2)
  14.     commondigrams=[]
  15.     coef1=len(digrams1)
  16.     coef2=len(digrams2)
  17.     for i in digrams1:
  18.         if i in digrams2:
  19.             commondigrams.append(i)
  20.             digrams2.remove(i)
  21.     return (2.0*len(commondigrams)/(coef1+coef2))
  22.    
  23. print (strike_a_match())
Add Comment
Please, Sign In to add comment