I have to define a function which finds a greatest number in a given list and its index. If there are two or more numbers that are the greatest, it should return the lowest index.
I'm not using .index to find its index. Is there any way to find its index with a for loop?
Supposing that I've already found the greatest number, max, I tried this:
lst = [1, 2, 3, 4, 5, 5]
ind = 0
for n in lst:
if max > n:
ind += 1
else:
ind += 0
return ind
But this only works properly when the numbers inside the list are ordered in increasing order. Is there any way to fix the code above to work properly with any kinds of lists by changing it a little bit?