python count items in list and keep their order of occurrance
<p>Given: a list, such as l=[4,4,4,4,5,5,5,6,7,7,7]
Todo: get the count of an element and keep their occurrence order, e.g.:
[(4,4),(5,3),(6,1),(7,3)]</p>

<p>I could do it with:</p>

<pre><code>tmpL    = [(i,l.count(i)) for i in l]
tmpS    = set()
cntList = [x for x in tmpL if x not in tmpS and not tmpS.add(x)]
</code></pre>

<p>But is there a better way? I have seen the link <a href="http://stackoverflow.com/questions/2290962/python-how-to-get-sorted-count-of-items-in-a-list">here</a>, but it sorts the counts and hence breaks the order.</p>

<p>Edit: performance is not an issue for the solution, preferable something built-in.</p>
