Python : How to find duplicates in a list and update these duplicate items by renaming them with a progressive letter added
I have a list of items like this: ['T1','T2','T2','T2','T2','T3','T3' ] I need to make sure that duplicates are renamed with a progressive letter added like this: ['T1','T2A','T2B','T2C','T2D','T3A','T3B'] but only if there is more than 1 occurrence of the same item. Also, is it possible to do so without generating a new list? Any ideas? from collections import Counter from string import ascii_uppercase as letters def gen(L): c = Counter(L) for elt, count in c.items(): if count == 1: yield elt else: for letter in letters[:count]: yield elt + letter Now: >>> L = ['T1','T2','T2','T2','T2','T3',