我有一个代表一个人的元组(ID,总分,就业天数,同行分数)。
我决定将每个元组放在一个列表中,如下所示:
aList = [ aTup, bTup, cTup.....]
我想根据以下规则将人们从最好到最差排名。 规则如下:
1. People(in this case the tuples) are sorted based on their overall score.
-->If the overall score is the same, sort it by the number of days employed.
-->If the days employed is the same, sort by peer score.
-->If the peer score is the same, sort by ID(the smaller ID gets preferenced.
python中有一个方法允许我实现这个吗?接近.sort()方法的东西?
答案 0 :(得分:1)
默认sort()
实际上是为元组做的。您只需要确保元组的格式为(score, days_employed, peer_score, id)
。