Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61637

Re: grab dict keys/values without iterating ?!

References (1 earlier) <almarsoft.6523303589308130554@news.gmane.org> <mailman.3885.1386762407.18130.python-list@python.org> <52a86c57$0$29992$c3e8da3$5496439d@news.astraweb.com> <20131211083051.65e3d501@bigbox.christie.dr> <CALwzidnSkiZ--jawug=dBZYxfqPTVA=xSVLeckctwfWDNdmhrg@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2013-12-11 18:05 -0700
Subject Re: grab dict keys/values without iterating ?!
Newsgroups comp.lang.python
Message-ID <mailman.3946.1386810804.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, Dec 11, 2013 at 6:02 PM, Ian Kelly <ian.g.kelly@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.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Re: grab dict keys/values without iterating ?! Tamer Higazi <tameritoke2@arcor.de> - 2013-12-11 12:07 +0200
  Re: grab dict keys/values without iterating ?! rusi <rustompmody@gmail.com> - 2013-12-11 05:31 -0800
    Re: grab dict keys/values without iterating ?! Roy Smith <roy@panix.com> - 2013-12-11 09:46 -0500
      Re: grab dict keys/values without iterating ?! rusi <rustompmody@gmail.com> - 2013-12-11 07:08 -0800
      Re: grab dict keys/values without iterating ?! Tim Chase <python.list@tim.thechases.com> - 2013-12-11 09:42 -0600
    Re: grab dict keys/values without iterating ?! Travis Griggs <travisgriggs@gmail.com> - 2013-12-11 09:19 -0800
    Re: grab dict keys/values without iterating ?! Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-11 18:09 +0000
  Re: grab dict keys/values without iterating ?! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-11 13:44 +0000
    Re: grab dict keys/values without iterating ?! Tim Chase <python.list@tim.thechases.com> - 2013-12-11 08:30 -0600
    Re: grab dict keys/values without iterating ?! Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-11 18:02 -0700
    Re: grab dict keys/values without iterating ?! Ian Kelly <ian.g.kelly@gmail.com> - 2013-12-11 18:05 -0700

csiph-web