Guest User

Untitled

a guest
Sep 13th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. def autocomplete(i, d):
  2. p = 'qwertyuiopasdfghjklzxcvbnm'
  3. t = ''.join([x for x in i if x.lower() in p])
  4. q = [
  5. w for w in d
  6. if t in w[:len(t)].lower()
  7. ]
  8. if len(q)<=5:
  9. return q
  10. else:
  11. return q[:5]
  12.  
  13.  
  14. print(autocomplete('a3i',[ 'abnormal', 'arm-wrestling', 'absolute',
  15. 'airplane', 'airport', 'amazing', 'apple', 'ball' ]))
  16.  
  17. q = [w for w in d if t in w[:len(t)].lower() and len(q)< 5]
  18.  
  19. import string
  20.  
  21. def autocomplete(i, d, threshold=5):
  22. i = i.casefold()
  23. t = ''.join([x for x in i if x in string.ascii_lowercase])
  24. return [w for cnt,w in enumerate(d) if w.casefold().startswith(t) and cnt < threshold]
  25.  
  26. import re
  27.  
  28. def autocomplete(i, d, threshold=5):
  29. t = re.sub('[^a-z]', '', i.casefold())
  30. return [w for cnt,w in enumerate(d) if w.casefold().startswith(t) and cnt < threshold]
Add Comment
Please, Sign In to add comment