I have a list, and I need to find the maximum element in the list and also record the index at which that max element is at.
This is my code.
list_c = [-14, 7, -9, 2]
max_val = 0
idx_max = 0
for i in range(len(list_c)):
if list_c[i] > max_val:
max_val = list_c[i]
idx_max = list_c.index(i)
return list_c, max_val, idx_max
Please help. I am just beginning to code and got stuck here.