Example 1: sorted python lambda
lst = [('candy','30','100'), ('apple','10','200'), ('baby','20','300')]
lst.sort(key=lambda x:x[1])
print(lst)
Example 2: sorted vs sort python
list = [4,8,2,1]
list.sort()
list = [4,8,2,1]
new_list = list.sorted()
Example 3: python sort
>>> student_tuples = [
... ('john', 'A', 15),
... ('jane', 'B', 12),
... ('dave', 'B', 10),
... ]
>>> sorted(student_tuples, key=lambda student: student[2])
[('dave', 'B', 10), ('jane', 'B', 12), ('john', 'A', 15)]
Example 4: sorted list python
sorted(iterable, key=None, reverse=False)
type(sorted(iterable, key=None, reverse=False)) = list
Example 5: python sort
nums = [4,8,5,2,1]
sorted_nums = sorted(nums)
print(sorted_nums)
print(nums)
nums.sort()
print(nums)
Example 6: pyhton built in sort
arr = [ 1, 3, 2]
arr.sort()