Answers for "how to sort list via another argument"

2

sort a list by values of another one python

numbers = [1, 2, 3]
letters = ['c', 'a', 'b']

#The numbers array sorted by the letters order
sorted_list = [number for letter, number in sorted(zip(letters, numbers))]

print(sorted_list)
#prints: [2, 3, 1]
Posted by: Guest on January-04-2021
2

sort two lists by one python

list1 = [3,2,4,1,1]
list2 = ['three', 'two', 'four', 'one', 'one2']
list1, list2 = zip(*sorted(zip(list1, list2)))
Posted by: Guest on October-15-2020

Code answers related to "how to sort list via another argument"

Python Answers by Framework

Browse Popular Code Answers by Language