Python - Find second smallest number

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

    As per the Python in-built function sorted

    sorted(my_list)[0]
    

    gives back the smallest number, and sorted(my_list)[1] does accordingly for the second smallest, and so on and so forth.

提交回复
热议问题