>>> students=[("john","A",15),("jane","B",12),("dave","B","10")]
>>> sorted(students,key=lambda s:s[2])
[("jane", "B", 12), ("john", "A", 15), ("dave", "B", "10")]
>>> sorted(students,key=lambda s:s[2])
[("jane", "B", 12), ("john", "A", 15), ("dave", "B", "10")]
>>> sorted(students,key=lambda s:s[2],reverse=True)
[("dave", "B", "10"), ("john", "A", 15), ("jane", "B", 12)]
>>> sorted(students, key=lambda s: s[2], reverse=True)
[("dave", "B", "10"), ("john", "A", 15), ("jane", "B", 12)]
>>> students = [("john", "A", 15), ("jane", "B", 12), ("dave", "B", 10)]
>>> sorted(students, key=lambda s: s[2])
[("dave", "B", 10), ("jane", "B", 12), ("john", "A", 15)]
>>> sorted(students, key=lambda s: s[2], reverse=True)
[("john", "A", 15), ("jane", "B", 12), ("dave", "B", 10)]-sharp-sharp-sharp
sources of topics and their own ideas
related codes
/ / Please paste the code text below (do not replace the code with pictures)