bsddb for k, v in db.items(): do order the numbers ?

Steve Holden steve at holdenweb.com
Mon Feb 28 12:40:18 EST 2005


Christopher De Vries wrote:

> On Mon, Feb 28, 2005 at 08:30:59AM -0800, martijn at gamecreators.nl wrote:
> 
>>WHen I use the code below and printing all the results i get this:
>>------
>>0 1 10
>>11 2 3
>>4 5 6
>>7 8 9
>>------
>>But I want
>>------
>>0 1 2
>>3 4 5
>>6 7 8
>>9 10 11
>>------
> 
> 
> If you want your key, value pairs in a certain order you have to sort them
> yourself. Dictionaries and bsddb keys are unsorted.
> 

Remember, also, that the keys are strings, so you'll need to convert 
them to numbers if you want them to sort numerically - otherwise "11" 
will come before "2".

regards
  Steve
-- 
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005                      http://www.pycon.org/
Steve Holden                           http://www.holdenweb.com/



More information about the Python-list mailing list