sorting a dictionary

Anders Hammarquist iko at cd.chalmers.se
Thu Feb 20 11:40:40 EST 2003


In article <b32m77$5ap$1 at ginger.mathworks.com>,
jcm  <joshway_without_spam at myway.com> wrote:
>user at domain.invalid wrote:
>
>> How about creating a sorted dictionary then? That is, add elements
>> to the dictionary in the order they are supposed to be in.
>> Is that not possible?
>
>Python dictionaries are unordered.  The best you can probably do is to
>keep a separate list of sorted keys.

Actually, you could use bsddb btree or recno databases on a temporary
file (there used to be a way to make an in-memory-only database, but
it seems to have disappeared - or at least I can't find it now). They
will let you build an ordered dictionary-like object.

/Anders

-- 
 -- Of course I'm crazy, but that doesn't mean I'm wrong.
Anders Hammarquist                                  | iko at cd.chalmers.se
Physics student, Chalmers University of Technology, | Hem: +46 31 88 48 50
G|teborg, Sweden.           RADIO: SM6XMM and N2JGL | Mob: +46 707 27 86 87




More information about the Python-list mailing list