def starter(l):
    cnt = Counter(l)
res = [None] * len(l)
return worker(cnt, res, len(l) - 1)

def worker(cnt, res, n):
    if n < 0:
        yield tuple(res)
python itertools permutations with tied values