Find min value in array > 0

前端 未结 7 1953
夕颜
夕颜 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:12

    def find_min_position(array):
        plus_array = [elem for elem in array if elem > 0]
        min_elem = min(plus_array)
        return min_elem, array.index(min_elem)
    
    In : find_min_position([4, 8, 0, 1, 5])
    Out: (1, 3)
    

提交回复
热议问题