Why are the results of the two implementations different?

>>> 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)

what result do you expect? What is the error message actually seen?

Mar.26,2021
The third element in the

tuple, one is by int and the other is by str type, and your key is sorted by the third element. Int and str cannot be compared in size.


python3.7 runs the error report directly. The elements are not exactly the same in


. One is '10' at the end, and the other is 10

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a2b1-2c1e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a2b1-2c1e4.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?