I am not sure that I am thinking correctly about this problem. I would like to write a function that takes a list with duplicates and adds an iterative suffix to βdeduplicateβ the list.
For instance:
dup_list = ['apple','banana','cherry','banana','cherry','orange','cherry']
Return Direction:
deduped = ['apple','banana1','cherry1','banana2','cherry2','orange','cherry3']
My instinct was to use the pop function, iterate through the list with a while statement, for example:
def dedup_suffix(an_list): dedup=[] for each in an_list: an_list.pop(an_list.index(each))
But:
>>> dedup_suffix(dup_list)
['apple', 'cherry', 'orange']
Appreciate any pointers.
source share