teamitems = [{'team':'France' , 'P':1 , 'GD':-3 , 'GS':1 , 'GA':4},
{'team':'Uruguay' , 'P':7 , 'GD':4 , 'GS':4 , 'GA':0},
{'team':'SouthAfrica' , 'P':4 , 'GD':-2 , 'GS':3 , 'GA':5},
{'team':'Mexico' , 'P':4 , 'GD':1 , 'GS':3 , 'GA':2}]
print sorted(teamitems ,key = lambda x:(x['P'],x['GD'],x['GS'],x['GA']),reverse=True)
以上代码实现了 按‘P',‘GD' ,‘GS' ,'GA' 四条件排序,reverse=True 表示降序
当然还可以
复制代码 代码如下:
from operator import itemgetter
print sorted(teamitems ,key = itemgetter('P','GD','GS','GA'),reverse=True)