Find min value in array > 0

前端 未结 7 2045
夕颜
夕颜 2021-02-07 05:49

I am looking to find the lowest positive value in an array and its position in the list. If a value within the list is duplicated, only the FIRST instance is of interest. This i

7条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-07 06:30

    add a filter then :

    myArray = [4, 8, 0, 1, 5]
    result = min(filter(lambda x: x > 0, myArray))
    print result # 1
    print myArray.index(result) # 3
    

提交回复
热议问题