You do not even need to install. You want to count every element with more than one occurrence. A collection counter along with dictionary knowledge should get you there.
from collections import Counter a = [1, 1, 1, 2, 2, 3, 4] removed = {k: v-1 for k, v in Counter(a).iteritems() if v > 1} >>> removed Out[8]: {1: 2, 2: 1}
source share