Python - Find second smallest number

前端 未结 16 1209
长发绾君心
长发绾君心 2020-11-28 10:35

I found this code on this site to find the second largest number:

def second_largest(numbers):
    m1, m2 = None, None
    for x in numbers:
        if x >         


        
16条回答
  •  野性不改
    2020-11-28 11:28

    There is a easy way to do . First sort the list and get the second item from the list.

    def solution(a_list):
    
        a_list.sort()
        print a_list[1]
    
    solution([1, 2, -8, -2, -10])
    

提交回复
热议问题