[Tutor] Sorting dictionary values
W.JarrettCampbell
W.JarrettCampbell
Wed, 15 Aug 2001 13:53:31 -0400
>
> I'm no longer subscribed to this list, but you guys were so helpful when I was learning Python a few months ago I thought I'd throw this one at you. Please respond to my email address directly in addition to any posts to the list since I'm no longer an active subscriber...thanks!
>
>
> Problem:
> ------
> I'm building a "Leader Board" application which tracks user names and displays the top 10 scores from a contest
W. Jarrett Campbell, Ph.D.
Member of Technical Staff
Yield Dynamics, Inc.
5838 Balcones Drive, Suite 101
Austin, TX 78731
512.323.9149 phone
512.415.1078 mobile
512.257.9503 fax>
> I'm using shelve/pickle for my persistence so basically what I'm confronted with is something that looks like this:
>
> userDB = {uniqueUserID:userData}
>
> where userData is itself a dictionary like
>
> userData = {"fname": "Jarrett",
> "lname": "Campbell",
> "email": "jarrett@ydyn.com",
> "score":"98.8"}
>
>
> What I need to do is find the 10 uniqueUserIDs from userDB where the value of "score" is the in the top 10 of all the records and sort them in order from highest to lowestW. Jarrett Campbell, Ph.D.
> Member of Technical Staff
> Yield Dynamics, Inc.
> 5838 Balcones Drive, Suite 101
> Austin, TX 78731
>
> 512.323.9149 phone
> 512.415.1078 mobile
> 512.257.9503 fax. Once that is done, I have a routine to display the leaderboard.
>
>
> Any suggestions for an efficient way to do this?
>
> Jarrett Campbell
> jarrett@ydyn.com
>