python sort according to list code example
Example 1: sort a list by values of another one python
numbers = [1, 2, 3]
letters = ['c', 'a', 'b']
sorted_list = [number for letter, number in sorted(zip(letters, numbers))]
print(sorted_list)
Example 2: how do i sort list in python
my_list = [9, 3, 1, 5, 88, 22, 99]
my_list = sorted(my_list, reverse=True)
print(my_list)
my_list = sorted(my_list, reverse=False)
print(my_list)
my_list.sort(reverse=True)
print(my_list)
print(my_list[::-1])
Example 3: 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)))
Example 4: how to sort a list in python
old_list = [3,2,1]
old_list.sort()