Python 根据另一个列表的排序索引对列表进行排序
我有两个列表,我想对其中一个(Python 根据另一个列表的排序索引对列表进行排序,python,python-3.x,Python,Python 3.x,我有两个列表,我想对其中一个(分数)按相反顺序排序,并获取相应的索引,以便对第二个(section\u id)进行排序 例如: section_id = [5, 6, 8, 14] scores = [4, 11, 13, 7] 新名单将是: sorted_reverse_scores = [13, 11, 7, 4] sorted_section_id = [8, 6, 14, 5] 你知道如何做到这一点吗 目前我唯一要做的是: sorted_reverse_scores = sectio
分数
)按相反顺序排序,并获取相应的索引,以便对第二个(section\u id
)进行排序
例如:
section_id = [5, 6, 8, 14]
scores = [4, 11, 13, 7]
新名单将是:
sorted_reverse_scores = [13, 11, 7, 4]
sorted_section_id = [8, 6, 14, 5]
你知道如何做到这一点吗
目前我唯一要做的是:
sorted_reverse_scores = section_id.sort(reverse=True)
输出
[13,11,7,4]
[8,6,14,5]
不要转储代码放一些解释我最初的列表是
部分id
和分数。我想根据排序的\u反向\u分数获得排序的\u部分\u id
。我更正了您现在可以验证的答案@zinon
section_id = [5, 6, 8, 14]
scores = [4, 11, 13, 7]
sorted_reverse_scores =[]
sorted_section_id =[]
for i in sorted(zip(scores,section_id),reverse=True):
sorted_reverse_scores.append(i[0])
sorted_section_id.append(i[1])
print(sorted_reverse_scores)
print(sorted_section_id)