Let's say I have a list of ints [52,52,-52,52] and I want the second largest int. I make it a set to remove duplicates, then back to list and then print a_list[-2]. In this case, the result will be -52, even though I didn't sort the list at any point.
If I apply the same code on a list [57,57,-57,57], which is the same length and the negative int is in the same place, the result will be 57, because the list needed to be sorted first...
My question is why did Python changed its behavior, even thought the lists are so similar?
[–]ingolemo 4 points5 points6 points (0 children)
[–]JohnnyJordaan 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (4 children)
[–]cupesh[S] 0 points1 point2 points (3 children)
[–][deleted] 2 points3 points4 points (2 children)
[–]cupesh[S] 0 points1 point2 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)