I was trying to find the second largest number in a list and thought of converting list into set, and to convert it back to list to eliminate the repeated values. Unfortunately, the negative value took the last index of the set (where I expected the greatest value to occupy the last index in the set). List contains both negative and positive values. When it was converted to set, the negative value took the last index.
n = 5
arr = [57, 57, 57, -57, 57]
res = list(set(arr))
print(res[-2])
I expected this to be my output:
-57
but the one I got was:
57
How do I find the second largest number in a list?