Intersection of two lists including duplicates?

You can use collections.Counter for this, which will provide the lowest count found in either list for each element when you take the intersection.

from collections import Counter

c = list((Counter(a) & Counter(b)).elements())

Outputs:

[1, 1, 2, 3, 4]

Simple with no additional imports and easy to debug :)

Disadvantage: The value of list b is changed. Work on a copy of b if you don't want to change b.

c = list()
for x in a:
    if x in b:
        b.remove(x)
        c.append(x)