Question: I would like to figure out if any deal is selected twice or more.

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.

The following code served me well, however by itself it throws an exception...

```
    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

```

...if I didn't initialize this before hand like the following.

```
    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

```

Is there anyway to simplify/combine this?

Answer: 
It looks like you want [`collections.Counter`](http://docs.python.org/library/collections.html#counter-objects).
Look at [collections.defaultdict](http://docs.python.org/library/collections.html#collections.defaultdict). It looks like you want `defaultdict(int)`.