autocomplete-like feature with a python dict

Posted by tipu on Stack Overflow See other posts from Stack Overflow or by tipu
Published on 2010-06-03T16:15:08Z Indexed on 2010/06/03 16:44 UTC
Read the original article Hit count: 134

Filed under:
|

In PHP, I had this line matches = preg_grep('/^for/', array_keys($hash)); What it would do is it would grab the words: fork, form etc. that are in $hash.

In Python, I have a dict with 400,000 words. It's keys are words I'd like to present in an auto-complete like feature (the values in this case are meaningless). How would I be able to return the keys from my dictionary that match the input?

For example (as used earlier), if I have

my_dic = t{"fork" : True, "form" : True, "fold" : True, "fame" : True}

and I get some input "for", It'll return a list of "fork", "form", "fold"

© Stack Overflow or respective owner

Related posts about python

Related posts about autocomplete