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: 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: References: <52A7AB8C.8030700@arcor.de> <52a86c57$0$29992$c3e8da3$5496439d@news.astraweb.com> <20131211083051.65e3d501@bigbox.christie.dr> From: Ian Kelly Date: Wed, 11 Dec 2013 18:05:29 -0700 Subject: Re: grab dict keys/values without iterating ?! To: Python 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Wed, Dec 11, 2013 at 6:02 PM, Ian Kelly 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.