Answers for "sort according to another list python"

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
0

sort list with respect to another list

list1 = [[1,1],[1,2],[1],[2,2]]
list2 = [2, 3, 1, 4]

zipped_lists = zip(list1, list2)
sorted_pairs = sorted(zipped_lists)

tuples = zip(*sorted_pairs)
c,v = [ list(tuple) for tuple in  tuples]
print(c)
Posted by: Guest on August-18-2020

Code answers related to "sort according to another list python"

Python Answers by Framework

Browse Popular Code Answers by Language