def main(x):
# x should at least has two elements
m1, m2 = (x[0], x[1]) if x[0] > x[1] else (x[1], x[0])
for i in range(2, len(x)):
if x[i] > m1:
m2 = m1
m1 = x[i]
elif x[i] > m2:
m2 = x[i]
return m1, m2
if __name__ == "__main__":
x = [1, 2, 3, 4, 10, -1]
y = [10, 9, 3, 1]
z = [3, 9, 9, 1]
print(main(x))
print(main(y))
print(main(z))
10, 4)
(10, 9)
(9, 9)
网友评论