與開始:
L = ['Ivan Connolly,50', 'Claudia Zingaro,50', 'Jeffie Honaker,50', 'Floria Rozar,49', 'Hyun Castleberry,48', 'Invalid Name,48', 'Cristi Authement,47', 'Yadira Millwood,47', 'Invalid Name,46']
要同時按多個鍵排序,首先,對排序的順序「輔助」鍵,你希望它是,例如,我們把它按字母順序排列忽略大小寫:
L.sort(key=str.lower)
給我們:
['Claudia Zingaro,50', 'Cristi Authement,47', 'Floria Rozar,49', 'Hyun Castleberry,48', 'Invalid Name,46', 'Invalid Name,48', 'Ivan Connolly,50', 'Jeffie Honaker,50', 'Yadira Millwood,47']
然後,我們按降序排序的得分字段:
L.sort(key=lambda L: int(L.rpartition(',')[2]), reverse=True)
這讓L
的最終結果:
['Claudia Zingaro,50', 'Ivan Connolly,50', 'Jeffie Honaker,50', 'Floria Rozar,49', 'Hyun Castleberry,48', 'Invalid Name,48', 'Cristi Authement,47', 'Yadira Millwood,47', 'Invalid Name,46']
+1,但你應該使用'INT(TEMP [1])'正確與1位數的得分處理。 – flornquake
@flornquake確實,正在修復 – TerryA
我可能會使用'temp [0] .rsplit(None,1)[:: - 1]'來獲取更多的標準名稱 –