[Solved] Find same elements in a list, and then change these elemens to tuple (f.e. 2 to (2,1))
To just add a count you could keep a set of itertools.count objects in a defaultdict: from itertools import count from collections import defaultdict counters = defaultdict(lambda: count(1)) result = [(n, next(counters[n])) for n in inputlist] but this would add counts to all elements in your list: >>> from itertools import count >>> from collections … Read more