Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def autocomplete(i, d):
- p = 'qwertyuiopasdfghjklzxcvbnm'
- t = ''.join([x for x in i if x.lower() in p])
- q = [
- w for w in d
- if t in w[:len(t)].lower()
- ]
- if len(q)<=5:
- return q
- else:
- return q[:5]
- print(autocomplete('a3i',[ 'abnormal', 'arm-wrestling', 'absolute',
- 'airplane', 'airport', 'amazing', 'apple', 'ball' ]))
- q = [w for w in d if t in w[:len(t)].lower() and len(q)< 5]
- import string
- def autocomplete(i, d, threshold=5):
- i = i.casefold()
- t = ''.join([x for x in i if x in string.ascii_lowercase])
- return [w for cnt,w in enumerate(d) if w.casefold().startswith(t) and cnt < threshold]
- import re
- def autocomplete(i, d, threshold=5):
- t = re.sub('[^a-z]', '', i.casefold())
- return [w for cnt,w in enumerate(d) if w.casefold().startswith(t) and cnt < threshold]
Add Comment
Please, Sign In to add comment