Guest User

Untitled

a guest
Sep 13th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 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. def autocomplete(i, d, threshold=5):
  20. p = 'qwertyuiopasdfghjklzxcvbnm'
  21. t = ''.join([x for x in i if x.casefold() in p])
  22. return [w for cnt,w in enumerate(d)
  23. if w.startswith(t.casefold()) and cnt < threshold]
Add Comment
Please, Sign In to add comment