How to find all positions of the maximum value in a list?

Bob picture Bob · Oct 21, 2010 · Viewed 347.8k times · Source

I have a list:

a = [32, 37, 28, 30, 37, 25, 27, 24, 35, 55, 23, 31, 55, 21, 40, 18, 50,
             35, 41, 49, 37, 19, 40, 41, 31]

max element is 55 (two elements on position 9 and 12)

I need to find on which position(s) the maximum value is situated. Please, help.

Answer

nmichaels picture nmichaels · Oct 21, 2010
a.index(max(a))

will tell you the index of the first instance of the largest valued element of list a.