'''Demonstrate that the Counter fast-path still calls hash twice per element (one on the getitem and again for the setitem). ''' from collections import Counter class HT(tuple): def __hash__(self): print('{hash: %r}' % self) return tuple.__hash__(self) def __eq__(self, other): print('{%r == %r}' % (self, other)) return tuple.__eq__(self, other) class HI(int): def __hash__(self): print('[hash: %r]' % self) return int.__hash__(self) def __eq__(self, other): print('[%r == %r]' % (self, other)) return int.__eq__(self, other) if __name__ == '__main__': n = 6 data = [HT((HI(i),)) for i in (list(range(n)) + list(range(n)))] Counter(data)