Skip to content

Instantly share code, notes, and snippets.

@Roxbili
Last active April 4, 2022 08:02
Show Gist options
  • Save Roxbili/e1cde16fbd18d535ef15cb2fc2c08311 to your computer and use it in GitHub Desktop.
Save Roxbili/e1cde16fbd18d535ef15cb2fc2c08311 to your computer and use it in GitHub Desktop.
Python实现一个列表依赖于另一个列表的排序结果重新排序

List

list1, list2 = (list(t) for t in zip(*sorted(zip(list1, list2))))

Numpy

people = ['Jim', 'Pam', 'Micheal', 'Dwight']
ages = [27, 25, 4, 9]

import numpy
people = numpy.array(people)
ages = numpy.array(ages)
inds = ages.argsort()
sortedPeople = people[inds]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment