Creating an Ordered Counter
<p>I've been reading into how <code>super()</code> works. I came across <a href="https://rhettinger.wordpress.com/2011/05/26/super-considered-super/" rel="noreferrer">this recipe</a> that demonstrates how to create an Ordered Counter:</p>

<pre><code>from collections import Counter, OrderedDict

class OrderedCounter(Counter, OrderedDict):
     'Counter that remembers the order elements are first seen'
     def __repr__(self):
         return '%s(%r)' % (self.__class__.__name__,
                            OrderedDict(self))
     def __reduce__(self):
         return self.__class__, (OrderedDict(self),)
</code></pre>

<p>For example:</p>

<pre><code>oc = OrderedCounter('adddddbracadabra')

print(oc)

OrderedCounter(OrderedDict([('a', 5), ('d', 6), ('b', 2), ('r', 2), ('c', 1)]))
</code></pre>

<p>Is someone able to explain how this magically works?</p>

<p>This also appears in the <a href="https://docs.python.org/3/library/collections.html#ordereddict-examples-and-recipes" rel="noreferrer">Python documentation</a>.</p>