def reverse_rank(id, score): values = list() for i, v in zip(id, score): values.append((i, (np.argmax(v), v[1]))) values = sorted(values, key=lambda item: (item[1][0], item[1][1]), reverse=True) return values
id = ['1', '2', '3', '4']
score = [(1,0.45), (0,0.32), (1,0.53), (0,0.53)]
ranked_res = reverse_rank(id, score)