list sort question

Joshua Muskovitz josh at open.com
Fri Oct 6 21:30:35 EDT 2000


You could create a dictionary where the last name is the key and the tuple
is the value.  (This assumes [a] you have a good function for figuring out
which part of the name is the "last name", and [b] that each entry's last
name is unique.)  Then, get the list of keys from the dictionary, sort it,
and then walk the sorted list, extracting the original tuples out of the
dictionary in the proper sort order.

Note, you can solve [b] by taking "Firstname M. Lastname" and instead of
extracting the lastname, converting it to "Lastname, Firstname M." or
whatever else would give you the proper sort order.  To solve [a], check the
dictionary for a previous entry with the same key, and then append something
trivial to the new string (like ".1" or something).  The assumption here
would be that two items with the same name sort ambiguously.  If you want to
sort same name entries by their email address, then you could append that,
for example.

Hope this helps.

-- josh




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----



More information about the Python-list mailing list