Python - Find second smallest number

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

    My favourite way of finding the second smallest number is by eliminating the smallest number from the list and then printing the minimum from the list would return me the second smallest element of the list. The code for the task is as below:

    mylist=[1,2,3,4]
    mylist=[x for x in mylist if x!=min(mylist)]  #deletes the min element from the list
    print(min(mylist))
    

提交回复
热议问题