Get frequency count of elements in an array
<p>Hi I have a list of values. I want to get another list with the amount of times every values in that list occurs. This is fairly easy, but I also need to have the values which are not present in the original list, to be present in the frequency list, but then with value 0. For example:</p>

<pre><code>I = [0,1,1,2,2,2,4,4,5,5,6,6,6,8,8,8]
</code></pre>

<p>What you expect:</p>

<pre><code>freqI = [1,2,3,2,2,2,3,3]
</code></pre>

<p>What I need:</p>

<pre><code>freqI = [1,2,3,0,2,2,3,0,3]
</code></pre>

<p>As you can see 3 and 7 are not present in <strong>I</strong>, though they are still accounted for in the frequency list. </p>

<p>My initial try ended up giving me the first kind of solution (with the intermediate values):</p>

<pre><code>d = {x:I.count(x) for x in I}

sorted_x = sorted(d.iteritems(), key=operator.itemgetter(0))
</code></pre>

<p>How can I get the frequency count (aka histogram) of my array, with the intermediate values present ?</p>
