I have an array below which consists of repeated strings. I want to find and replace those strings, but each time a match is made I want to change the value of the replace strin
Assuming you want the array sorted :
import collections
counter = collections.Counter(SampleArray)
res = []
for key in sorted(counter.keys()):
if counter[key] == 1:
res.append(key)
else:
res.extend([key+str(i) for i in range(1, counter[key]+1)])
>>> res
['champ', 'king1', 'king2', 'mak1', 'mak2', 'mak3']