Since it is used relatively for competitive programming, it is only a memorandum. There are 2 patterns
Input
numbers = [9,2,5,4,7]
numbers.sort()
print(numbers)
print(numbers[-2])
Output
[2,4,5,7,9]
7
Input
numbers = [8, 8, 1, 4, 3]
a = sorted(set(numbers))
print(a)
print(a[-2])
Output
[1 ,3 ,4 ,8]
4
Recommended Posts