I'm trying to get the index of the smallest number in a list, confused by this result.....
nums = [4,0,100] smallest = min(enumerate(nums)) print("smallest = ", smallest) Printout: smallest = (0,4)
Shouldn't it be: smallest = (1,0)
You need to use key=lambda x: x[1]) to say min function to check for the minimum value present in the second index, by default it checks in the first index, in which you are having an index value. So, it results (0,4) which is obvious.
Try this,
>>> min(enumerate(nums), key=lambda x: x[1]) (1, 0)