您可以将每个计数器转换为键、值(项)元组的冻结集,然后将其用作传递给计数器的元素(因为冻结集是可散列的),例如:
import random
from collections import Counter
random.seed(42)
counts = [Counter([random.randint(0, 2) for _ in range(10)]) for _ in range(10)]
uniques = {frozenset(e.items()): e for e in counts}
counters_count = Counter(map(lambda e : frozenset(e.items()), counts))
for key, count in counters_count.items():
print uniques[key], count
输出
Counter({0: 7, 1: 2, 2: 1}) 1
Counter({1: 4, 2: 4, 0: 2}) 1
Counter({0: 4, 1: 4, 2: 2}) 2
Counter({0: 4, 1: 3, 2: 3}) 1
Counter({0: 5, 2: 3, 1: 2}) 1
Counter({1: 5, 2: 5}) 1
Counter({0: 5, 1: 4, 2: 1}) 1
Counter({0: 4, 2: 4, 1: 2}) 1
Counter({2: 4, 0: 3, 1: 3}) 1