1>>> student_tuples = [
2... ('john', 'A', 15),
3... ('jane', 'B', 12),
4... ('dave', 'B', 10),
5... ]
6>>> sorted(student_tuples, key=lambda student: student[2]) # sort by age
7[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
8
1>>> x = [1 ,11, 2, 3]
2>>> y = sorted(x)
3>>> x
4[1, 11, 2, 3]
5>>> y
6[1, 2, 3, 11]
7
1nums = [4,8,5,2,1]
2#1 sorted() (Returns sorted list)
3sorted_nums = sorted(nums)
4print(sorted_nums)#[1,2,4,5,8]
5print(nums)#[4,8,5,2,1]
6
7#2 .sort() (Changes original list)
8nums.sort()
9print(nums)#[1,2,4,5,8]
1gList = [ "Rocket League", "Valorant", "Grand Theft Autu 5"]
2gList.sort()
3# OUTPUT --> ['Grand Theft Auto 5', 'Rocket League', 'Valorant']
4# It sorts the list according to their names
1arr = [1,4,2,7,5,6]
2#sort in ascending order
3arr = arr.sort()
4
5#sort in descending order
6arr = arr.sort(reverse = True)