You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
def second_largest(numbers):
|
|
count = 0
|
|
n1 = n2 = float('-inf')
|
|
for x in numbers:
|
|
count += 1
|
|
if x > n2:
|
|
if x >= n1:
|
|
n1, n2 = x, n1
|
|
else:
|
|
n2 = x
|
|
return n2 if count >= 2 else None
|
|
|
|
print(second_largest([1, 2, -8, -2, 0])) |