Given a list, the task is to write a Python program to mark the duplicate occurrence of elements with progressive occurrence number.
Input : test_list = ['gfg', 'is', 'best', 'gfg', 'best', 'for', 'all', 'gfg']
Output : ['gfg1', 'is', 'best1', 'gfg2', 'best2', 'for', 'all', 'gfg3']
Explanation : gfg's all occurrence are marked as it have multiple repetitions(3).
Input : test_list = ['gfg', 'is', 'best', 'best', 'for', 'all']
Output : ['gfg', 'is', 'best1', 'best2', 'for', 'all']
Explanation : best's all occurrence are marked as it have multiple repetitions(2).
In this, in order to get the duplicate count, the list is sliced to current element index, and count of occurrence of that element till current index is computed using count() and append.
The original list is : ['gfg', 'is', 'best', 'gfg', 'best', 'for', 'all', 'gfg']
Duplicates marked List : ['gfg1', 'is', 'best1', 'gfg2', 'best2', 'for', 'all', 'gfg3']
Similar to the above method, the only difference being map() is used to get a function using lambda to extend to whole list elements.
The original list is : ['gfg', 'is', 'best', 'gfg', 'best', 'for', 'all', 'gfg']
Duplicates marked List : ['gfg1', 'is', 'best1', 'gfg2', 'best2', 'for', 'all', 'gfg3']
OutputThe original list is : ['gfg', 'is', 'best', 'gfg', 'best', 'for', 'all', 'gfg']
Duplicates marked List : ['gfg1', 'is', 'best1', 'gfg2', 'best2', 'for', 'all', 'gfg3']