【发布时间】:2020-09-08 08:57:40
【问题描述】:
我有一个数组:
one = ['telephone', 'first_name', 'second_name']
另一个数组:
two = ['first_name', 'second_name', 'telephone']
我可以像one 一样对two 进行排序吗?没有特定的顺序吗?我一直希望它订购为one
这个函数:
def sort_list(list1, list2):
zipped_pairs = zip(list2, list1)
z = [x for _, x in (zipped_pairs)]
return z
three = sort_list(two, one)
这是对我不想要的压缩数组进行排序
【问题讨论】:
-
它不一样,这就是我尝试过的。因为它正在订购不是我想要的压缩列表
-
这两个列表是否总是包含相同的项目?为什么不直接复制列表?另外,“这是对压缩数组进行排序”是什么意思?你得到的输出与你想要的输出是什么?
-
是什么阻止你做
two[:] = one左右?我不明白你在这里想要达到什么目的。您在寻找排序索引吗?
标签: python arrays python-3.x list sorting