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


Groups > comp.lang.python > #61553

Re: grab dict keys/values without iterating ?!

Date 2013-12-11 12:07 +0200
From Tamer Higazi <tameritoke2@arcor.de>
Subject Re: grab dict keys/values without iterating ?!
References <52A7AB8C.8030700@arcor.de> <52A7AB8C.8030700@arcor.de> <almarsoft.6523303589308130554@news.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.3885.1386762407.18130.python-list@python.org> (permalink)

Show all headers | View raw


Hi Dave!

You were absolutely right.
I don't want to iterate the entire dict to get me the key/values

Let us say this dict would have 20.000 entries, but I want only those 
with "Aa" to be grabed.
Those starting with these 2 letters would be only 5 or 6 then it would 
take a lot of time.

In which way would you prefer to store the data, and which functions or 
methods would you use effectively to accomplish this task ?

I deeply apologize of not defining the question more defined. English is 
not my mother tongue.
I'll do my best next time.


Thanks



Tamer

On 11.12.2013 06:47, Dave Angel wrote:
> 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.
>

Back to comp.lang.python | Previous | NextNext 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