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])
5 ответов
+ 4
print(sorted(input().split())[::-1][1])
but Diego's slice is shorter
print(sorted(input().split())[-2])
+ 3
Is there any reason you use dict.fromkeys()?
+ 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().
0
You should just say result[1]
Assuming youve sorted the list, thisll give the second value of the list
0
no special reason im using dict.fromkeys. just found it online and wantes to try it.