How to combine initialization and assignment of dictionary in Python?
<p>I would like to figure out if any deal is selected twice or more.</p>

<p>The following example is stripped down for sake of readability. But in essence I thought the best solution would be using a dictionary, and whenever any deal-container (e.g. deal_pot_1) contains the same deal twice or more, I would capture it as an error.</p>

<p>The following code served me well, however by itself it throws an exception...</p>

<pre><code>    if deal_pot_1:
       duplicates[deal_pot_1.pk] += 1

    if deal_pot_2:
        duplicates[deal_pot_2.pk] += 1

    if deal_pot_3:
        duplicates[deal_pot_3.pk] += 1
</code></pre>

<p>...if I didn't initialize this before hand like the following.</p>

<pre><code>    if deal_pot_1:
       duplicates[deal_pot_1.pk] = 0

    if deal_pot_2:
        duplicates[deal_pot_2.pk] = 0

    if deal_pot_3:
        duplicates[deal_pot_3.pk] = 0
</code></pre>

<p>Is there anyway to simplify/combine this?</p>
