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


Groups > comp.lang.python > #61637

Re: grab dict keys/values without iterating ?!

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.060
X-Spam-Evidence '*H*': 0.88; '*S*': 0.00; 'nested': 0.07; 'iterate': 0.09; 'subject:keys': 0.09; 'entries.': 0.16; 'lookups': 0.16; 'prefix,': 0.16; 'subject:values': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'wed,': 0.18; 'example': 0.22; '(in': 0.22; 'preferred': 0.22; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'words': 0.29; 'dec': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'included': 0.31; "skip:' 10": 0.31; 'node': 0.31; 'ago': 0.33; 'except': 0.35; 'case,': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'structure': 0.39; 'though,': 0.39; 'to:addr:python.org': 0.39; 'space': 0.40; 'ian': 0.60; 'new': 0.61; 'first': 0.61; 'save': 0.62; 'more': 0.64; 'deeply': 0.69; 'completion': 0.78; 'potentially': 0.81; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=2WlbI0Vcc6hTUJlASyX7KoZJV99QRdxHP7oOtLUM5rA=; b=beTUfnaUorxaP4oXnzt0sA6J7Yg+1FLN9uTIwgDEIpnwAqjebTAstE8OM1/eGC9Oja IW3cf+JQnXhnhc4ynxjh/yes9LAk8uLMeC3Xs3nLQK7++12e35ZJGfYo5FgB1fqmq0z0 0B18klpkVfSVI8Vo2VnpX506/YNI6lN2I8uBqCXiFxfOrvbKIRweEtBW0aNXcXIwP70Q ngHda2MmQMu6qfMjVhlB2mLGKlN4NKqns54mJDf75nPlUWBCzebW0GX8DSGv2eted+qU gQdLaw6Hz/MHfobhlqWhmknFv2BEvfXq05thgz6mcplctP95gtYi19Prtf+zdJxeltb+ cfRg==
X-Received by 10.220.3.144 with SMTP id 16mr1916940vcn.33.1386810369164; Wed, 11 Dec 2013 17:06:09 -0800 (PST)
MIME-Version 1.0
In-Reply-To <CALwzidnSkiZ--jawug=dBZYxfqPTVA=xSVLeckctwfWDNdmhrg@mail.gmail.com>
References <52A7AB8C.8030700@arcor.de> <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 Wed, 11 Dec 2013 18:05:29 -0700
Subject Re: grab dict keys/values without iterating ?!
To Python <python-list@python.org>
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3946.1386810804.18130.python-list@python.org> (permalink)
Lines 25
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1386810804 news.xs4all.nl 2877 [2001:888:2000:d::a6]:59308
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:61637

Show key headers only | 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