Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 根据另一个列表的排序索引对列表进行排序_Python_Python 3.x - Fatal编程技术网

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)