Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder3.xlned.com!newsfeed.xs4all.nl!newsfeed3.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'differently.': 0.09; 'iterate': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:keys': 0.09; 'stored': 0.12; 'assumptions': 0.16; 'dict': 0.16; 'guessing': 0.16; 'iterating': 0.16; 'key/value': 0.16; 'objection': 0.16; 'pairs': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'subject:values': 0.16; 'wording': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'example': 0.22; 'header:User-Agent:1': 0.23; 'subject:/': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; "doesn't": 0.30; 'dec': 0.30; "i'm": 0.30; 'code': 0.31; 'keys': 0.31; 'could': 0.34; 'but': 0.35; 'there': 0.35; '+0200,': 0.36; "i'll": 0.36; 'two': 0.37; 'list': 0.37; 'to:addr :python-list': 0.38; 'structure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'letters': 0.60; 'entire': 0.61; 'further': 0.61; "you'll": 0.62; 'grab': 0.64; 'ambiguous': 0.84; 'guessed': 0.84; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dave Angel Subject: Re: grab dict keys/values without iterating ?! Date: Tue, 10 Dec 2013 23:47:10 -0500 References: <52A7AB8C.8030700@arcor.de> <52A7AB8C.8030700@arcor.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Gmane-NNTP-Posting-Host: dpc6744192057.direcpc.com In-Reply-To: <52A7AB8C.8030700@arcor.de> User-Agent: Groundhog Newsreader for Android 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: 1386737168 news.xs4all.nl 2833 [2001:888:2000:d::a6]:55963 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:61525 On Wed, 11 Dec 2013 02:02:20 +0200, Tamer Higazi wrote: > Is there a way to get dict by search terms without iterating the entire > dictionary ?! > I want to grab the dict's key and values started with 'Ar'... Your wording is so ambiguous that each respondent has guessed differently. I'm guessing that you want all key/value pairs for which the key begins with the two letters 'Ar' I'm guessing further that your objection to iterating the entire dictionary is not code size but performance. If both assumptions are valid then I'll point out that a dict has no ordering to it. If you want an approach that doesn't iterate over the entire structure you'll need to store the data differently. For example if you stored all the keys in a sorted list you could use bisect. -- DaveA