algorithm - use Python to quickly generate autocomplete suggestions -


i have set all_words of 6.5 million words. how can use python generate list of words begin given string?

obviously, can like

def completions(word_start):     ell = len(word_start)     return [w w in all_words if w[: ell] == word_start] 

this works takes on order of second. faster way generate full list?

i guess fastest , space-efficient data structure kind of problems use prefix tree. after have parsed collection of words tree, lookup time should pretty fast. there seems python implementation out there.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -