I was asked to define a function that takes a list as an argument and returns the index of the smallest value.
This is what I came up with:
def index_finder(lst): """ parameters: lst of type list returns: index of the lst's smallest value """ for i in range(len(lst)): if lst[i]==index(lst): print(i) return None def index(lst): """ parameters: lst of type list returns: the smallest value of that lst """ if len(lst)==1: return lst if lst<lst: lst.append(lst) return index(lst[1:]) index_finder([3,2,4,0,1,5,-6,2,5])
This will output the following:
As you can see I had to use separate functions in order to get the result. Is there a concise, yet simple way to do this?
By concise I mean short and by simple I mean using only simple functions.