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


Groups > comp.lang.python > #61525

Re: grab dict keys/values without iterating ?!

From Dave Angel <davea@davea.name>
Subject Re: grab dict keys/values without iterating ?!
Date 2013-12-10 23:47 -0500
References <52A7AB8C.8030700@arcor.de> <52A7AB8C.8030700@arcor.de>
Newsgroups comp.lang.python
Message-ID <mailman.3868.1386737168.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Wed, 11 Dec 2013 02:02:20 +0200, Tamer Higazi 
<tameritoke2@arcor.de> 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

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


Thread

Re: grab dict keys/values without iterating ?! Dave Angel <davea@davea.name> - 2013-12-10 23:47 -0500

csiph-web