def list_difference25(a, b):
    count = defaultdict(int)
for x in a:
    count[x] += 1
for x in b:
    count[x] -= 1
diff = []
for x in a:
    if count[x] > 0:
        count[x] -= 1
diff.append(x)
return diff
Разница между двумя списками с дубликатами в Python