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 -

android - IBM Worklight 6.1 [Application Error] There was a network error (file:///android_asset/www/index.html) -