web123456

python3 sorted(t, key=lambda x:x[0]) sorted problem

python3
 C = [('e', 4, 2), ('a', 2, 1), ('c', 5, 4), ('b', 3, 3), ('d', 1, 5)]
 print(sorted(C, key=lambda y: y[0]))
 #Output[('a', 2, 1), ('b', 3, 3), ('c', 5, 4), ('d', 1, 5), ('e', 4, 2)]
 print(sorted(C, key=lambda x: x[0]))
 #[('a', 2, 1), ('b', 3, 3), ('c', 5, 4), ('d', 1, 5), ('e', 4, 2)]
 print(sorted(C, key=lambda x: x[2]))
 [('a', 2, 1), ('e', 4, 2), ('b', 3, 3), ('c', 5, 4), ('d', 1, 5)]

key=lambda element: element [field index]

for example   print(sorted(C, key=lambda x: x[2]))   

x:x[] letters can be modified at will, and the sorting method is sorted according to the dimensions in brackets[], [0] is sorted according to the first dimension, and [2] is sorted according to the third dimension