не делал никаких тестов, но это не должно работать плохо (даже если он повторяется по списку дважды):
from collections import Counter
from random import randint
eles = [randint(0, 10) for i in range(30)]
counter = Counter(eles)
most_common_element, number_of_occurrences = counter.most_common(1)[0]
indices = [i for i, x in enumerate(eles) if x == most_common_element]
print(most_common_element, number_of_occurrences, indices)
и индексы (вторая итерация) можно найти лениво в выражении генератора:
indices = (i for i, x in enumerate(eles) if x == most_common_element)
если вам нужно позаботиться о том, чтобы несколько элементов были наиболее распространенными, это может сработать для вас:
from collections import Counter
from itertools import groupby
from operator import itemgetter
eles = [1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5]
counter = Counter(eles)
_key, group = next(groupby(counter.most_common(), key=itemgetter(1)))
most_common = dict(group)
indices = {key: [] for key in most_common}
for i, x in enumerate(eles):
if x in indices:
indices[x].append(i)
print(most_common)
print(indices)
вы, конечно, все равно можете сделать indices
ленивым, как и выше.