0

Runner up.

Input numbers and get the second highest score (runner up score). I've found this solution but instead of giving me the second highest score in value, it seems to print the second from last number in the index? Also, what's an array? n = int(input()) arr = map(int, input().split()) result = sorted(list(dict.fromkeys(arr))) print(result[len(result)-2])

17th May 2019, 3:21 AM
tristach605
tristach605 - avatar
5 Réponses
+ 4
print(sorted(input().split())[::-1][1]) but Diego's slice is shorter print(sorted(input().split())[-2])
17th May 2019, 5:14 AM
David Ashton
David Ashton - avatar
+ 3
Is there any reason you use dict.fromkeys()?
17th May 2019, 4:50 AM
Anna
Anna - avatar
+ 1
1. Python doesn't have built-in support for arrays. You need to import a module for that. https://docs.python.org/3/library/array.html 2. You're actually printing the second highest score. You can also do "result[-2]", which is faster than using len().
17th May 2019, 4:14 AM
Diego
Diego - avatar
0
You should just say result[1] Assuming youve sorted the list, thisll give the second value of the list
17th May 2019, 3:54 AM
Trigger
Trigger - avatar
0
no special reason im using dict.fromkeys. just found it online and wantes to try it.
17th May 2019, 5:08 AM
tristach605
tristach605 - avatar