Guest User

Untitled

a guest
Oct 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. from difflib import SequenceMatcher
  2. class Dictionary:
  3. def __init__(self,words):
  4. self.words=words
  5. self.p,self.l1,self.l2=0,0,0
  6. self.dict1={}
  7. def find_most_similar(self,term):
  8. p=0
  9. for i in self.words:
  10. for j in term:
  11. l1=term.count(j)
  12. l2=i.count(j)
  13. if(l1==l2):
  14. p=p+1
  15. #print(len(i),len(check))
  16. if((len(term)==len(i)-1)|(len(term)==len(i)+1)):
  17. p=p+1
  18. self.dict1[i]=p
  19. p=0
  20. #print(dict1)
  21. inverse = [(value, key) for key, value in self.dict1.items()]
  22. m,c=0,""
  23. for i in self.dict1:
  24. v=self.dict1[i]
  25. if(v>=m):
  26. m=v
  27. c=(i)
  28. print(c)
  29. print(self.dict1)
  30.  
  31. words=['cherry', 'peach', 'pineapple', 'melon', 'strawberry', 'raspberry', 'apple', 'coconut', 'banana']
  32. test_dict=Dictionary(words)
  33. while(True):
  34. x=input("---")
  35. test_dict.find_most_similar(x)
Add Comment
Please, Sign In to add comment