Python - Find second smallest number

前端 未结 16 1216
长发绾君心
长发绾君心 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:17

    def SecondSmallest(x):
        lowest=min(x[0],x[1])
        lowest2 = max(x[0],x[1])
        for item in x:
             if item < lowest:
                lowest2 = lowest
                lowest = item
             elif lowest2 > item and item > lowest:
                lowest2 = item
        return lowest2
    
    SecondSmallest([10,1,-1,2,3,4,5])
    

提交回复
热议问题