I expanded and added as a new question.
I have a list:
li = [2, 3, 1, 4, 2, 2, 2, 3, 1, 3, 2]
Then I recognize which value occurs most often, which value I retain in the variable i2
:
f = {}
for item in li:
f[item] = f.get(item, 0) + 1
for i in f:
if f[i]==int(max(f.values())):
i2 = i
Later all values that repeat are increased by 10, but in addition to the maximum values. This is the code that I use:
for i in range(len(li)):
for x in range(i + 1, len(li)):
if li[i] == li[x] and li[i] != i2:
li[x] = li[x] + 10
After this operation I get:
li = [2, 3, 1, 4, 2, 2, 2, 13, 11, 23, 2]
As you can see, the most common value is 2, so it remains unchanged. For example, 3 occurs three times and from all three new values are created 3, 3 + 10, 3 + 20. And the same with the rest of the value (except 2). But if the two maximum values are next to each other (or in a longer sequence), I would like to increase each subsequent in such a sequence one by 10, and get:
li = [2, 3, 1, 4, 2, 12, 22, 13, 11, 23, 2]
How to do it?
I could now do the same on a new loop, but already on the changed list and applying the condition li[i] == li[i+1]
, but maybe it can be done in the current loop?