On Wed, Dec 11, 2013 at 6:02 PM, Ian Kelly <ian.g.ke...@gmail.com> wrote: > This is what I did not so long ago when writing a utility for > typeahead lookup, except that to save some space and time I only > nested the dicts as deeply as there were still multiple entries. As > an example of what the data structure looked like: > > lookups = { > 'a': { > 'l': { > 'g': 'algebra', > 'p': 'alphanumeric', > }, > 's': 'asterisk', > }, > 'b': 'bobcat', > ... > } > > It does make the update process more complicated though, as adding new > words potentially requires existing words to be nested deeper than > they are currently.
And I'm simplifying that a bit, because I also included at each node the preferred (in my case, the first alphabetically) completion for that prefix, to avoid the need to iterate over the subtree. -- https://mail.python.org/mailman/listinfo/python-list