grab dict keys/values without iterating ?!

Tamer Higazi tameritoke2 at
Wed Dec 11 13:48:58 CET 2013

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 of data and requests are high.

I am thinking of scalability. Of course I could use the MongoDB as well. 
But this is from my side for THESE KIND of things not desired.
I am thinking of making Files through objects in the ZODB Database 
persistent, and relational databases on long time make me sick....

I will workout a bselect sollution for my problem!

Thanks for your support.


On 11.12.2013 14:10, Peter Otten wrote:
> 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
>> 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 ?
> Well, Dave already gave one approach:
> [Dave Angel]
>> For example if you stored all the keys in a sorted list you could use
>> bisect.
> See also
> Another option would be to use a database. Assuming the table 'lookup' has
> two columns 'key' and 'value' you'd get the matching rows with
> select key, value from lookup where key like 'Aa%';
> A lightweight database that comes with Python is sqlite:

More information about the Python-list mailing list