Should I use a dictionary?

Aahz Maruch aahz at panix.com
Tue Jun 26 00:07:07 EDT 2001


In article <Xns90CCC3D73603gustaflalgonetse at 194.213.69.148>,
Gustaf Liljegren <gustafl at algonet.se> wrote:
>
>I have an object type for e-mail messages based on the rfc822
>module. After picking out some messages from several sources, I want
>to sort them in order of the date property of the message object (as
>far as I understand, everything in this process needs to be kept in
>memory). Anyway, the problem is that I need some hints about how to
>sort the messages, as they are not sorted in way I get them.
>
>One idea I came up with was to put the date property of the message
>object as a key in a dictionary, and let the rest of the message be
>the value! But even if it would work, I think it's ugly. If someone
>can convince me that it's not ugly, or give a better (i.e. faster)
>solution, I'd be happy.

For this purpose, a list is probably better, with the values being a
tuple of (<date>, <message>).  The problem is that dicts want the key to
be unique, and dealing with key collisions in this case is almost
certainly more trouble than it's worth.
-- 
                      --- Aahz  <*>  (Copyright 2001 by aahz at pobox.com)

Hugs and backrubs -- I break Rule 6                 http://www.rahul.net/aahz/
Androgynous poly kinky vanilla queer het Pythonista   

"Those who do not remember the past are condemned to repeat it."



More information about the Python-list mailing list