I have been doing a challenge to find a runner up score from a list
or
You can say I was trying to find the second largest from a list.
array = '57 57 -57 57'
print(list(set(sorted(array.split(' '))))[-2])
But on every execution the program returning different Output.
57
-57
57
-57
Why it is behaving like this??
Change it to this:
array = '57 57 -57 57'
print(list(sorted(set(array.split(' '))))[-2])
'set' doesn't preserve the order, so first get the set value and then sort it.