Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tamer Higazi
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

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Peter Otten
Tamer Higazi wrote: 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

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tamer Higazi
Hi Peter! I got the message I know that I could have used a database. I am using for a good reason the ZODB Database. I am making things in the ZODB Database persistent, I don't like to distribute among machines. Making use of sqlite, won't give me the possibility to scale as the amount

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread rusi
Reordering to un-top-post. On 11.12.2013 06:47, Dave Angel wrote: 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

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Steven D'Aprano
On Wed, 11 Dec 2013 12:07:08 +0200, Tamer Higazi wrote: 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

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 13:44, Steven D'Aprano wrote: If necessary, I would consider having 26 dicts, one for each initial letter: data = {} for c in ABCDEFGHIJKLMNOPQRSTUVWXYZ: data[c] = {} then store keys in the particular dict. That way, if I wanted keys starting with Aa, I would only

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Roy Smith
In article 3efc283f-419d-41b6-ad20-c2901c3b9...@googlegroups.com, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread rusi
On Wednesday, December 11, 2013 8:16:12 PM UTC+5:30, Roy Smith wrote: rusi wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ I agree that a

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Tim Chase
On 2013-12-11 09:46, Roy Smith wrote: The problem is, that doesn't make a whole lot of sense in Python. The cited implementation uses dicts at each level. By the time you've done that, you might as well just throw all the data into one big dict and use the full search string as the key. It

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Mark Lawrence
On 11/12/2013 00:02, Tamer Higazi wrote: Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'} I want to grab the dict's key

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Travis Griggs
On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/ My thoughts exactly! If you wade through

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Mark Lawrence
On 11/12/2013 17:19, Travis Griggs wrote: On Dec 11, 2013, at 5:31 AM, rusi rustompm...@gmail.com wrote: The classic data structure for this is the trie: General idea: http://en.wikipedia.org/wiki/Trie In python: http://stackoverflow.com/questions/11015320/how-to-create-a-trie-in-python/

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 7:30 AM, Tim Chase python.l...@tim.thechases.com wrote: On 2013-12-11 13:44, Steven D'Aprano wrote: If necessary, I would consider having 26 dicts, one for each initial letter: data = {} for c in ABCDEFGHIJKLMNOPQRSTUVWXYZ: data[c] = {} then store keys in the

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Ian Kelly
On Wed, Dec 11, 2013 at 6:02 PM, Ian Kelly ian.g.ke...@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

Re: grab dict keys/values without iterating ?!

2013-12-11 Thread Dan Stromberg
On Tue, Dec 10, 2013 at 4:02 PM, Tamer Higazi tamerito...@arcor.de wrote: Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','

grab dict keys/values without iterating ?!

2013-12-10 Thread Tamer Higazi
Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'} I want to grab the dict's key and values started with 'Ar'... I could

Re: grab dict keys/values without iterating ?!

2013-12-10 Thread MRAB
On 11/12/2013 00:02, Tamer Higazi wrote: Hi people! Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'} I want to grab the dict's key

Re: grab dict keys/values without iterating ?!

2013-12-10 Thread Tim Chase
On 2013-12-11 02:02, Tamer Higazi wrote: Is there a way to get dict by search terms without iterating the entire dictionary ?! Let us assume I have: {'Amanda':'Power','Amaly':'Higgens','Joseph':'White','Arlington','Black','Arnold','Schwarzenegger'}

Re: grab dict keys/values without iterating ?!

2013-12-10 Thread Ben Finney
Tamer Higazi tamerito...@arcor.de writes: Is there a way to get dict by search terms without iterating the entire dictionary ?! (A language note: you may be unaware that “?!” does not connote a simple question, but outrage or incredulity or some other indignant expression. This implies not a

Re: grab dict keys/values without iterating ?!

2013-12-10 Thread Dave Angel
On Wed, 11 Dec 2013 02:02:20 +0200, Tamer Higazi tamerito...@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