Most elegant way to count integers in a list
<p>I am looking for the most elegant way to do the following:</p>

<p>Let's say that I want to count number of times each integer appears in a list; I could do it this way:</p>

<pre><code>x = [1,2,3,2,4,1,2,5,7,2]

dicto = {}

for num in x:
    try:
        dicto[num] = dicto[num] + 1
    except KeyError:
        dicto[num] = 1
</code></pre>

<p>However, I think that </p>

<pre><code>try:
    dicto[num] = dicto[num] + 1
except KeyError:
    dicto[num] = 1
</code></pre>

<p>is not the most elegant ways to do it; I think that I saw the above code replaced by a single line. What is the most elegant way to do this?</p>

<p>I realized that this might be a repeat, but I looked around and couldn't find what I was looking for.</p>

<p>Thank You in advance.</p>
