Sorting a dictionary field belonging to a list

Jocknerd jocknerd1 at yahoo.com
Fri Sep 17 14:51:22 EDT 2004


I have a list called teamlist which contain dictionaries of teams.  These
are the fields in my team dictionary:

name, won, lost, tied, pf, pa

To print standings I do the following:

def printStandings(teamlist):
   for team in teamlist:
      print (team['name'], team['won'], team['lost'], team['tied'],
      team['pf'], team['pa'])

My question is how would I go about sorting the output based on team['pf']
for instance?



More information about the Python-list mailing list