Python Chapter 7 Exercises plus(10)

Please complete the following function fun10, data is a one-dimensional integer list, this function can find the position of the nth smallest value.
Note that the index starts from 0, so n-1 is required at the end

def fun10(data,n):
    """
    Arg:
        data : a list and a number as input; e.g. [1,2,1,1,3,4,3,1,1,2,1,1,2],5
    return a index of the target; e.g. 8
    """
    data1=np.array(data)
    res=np.where(data1==np.min(data1))[0]
    return res[n-1]

Guess you like

Origin blog.csdn.net/qq_53029299/article/details/115281905