Learning Python and using dictionaries
<p>I'm working through exercises in <a href="http://homepage.mac.com/s_lott/books/python/html/p02/p02c05_maps.html" rel="nofollow">Building Skills in Python</a>, which to my knowledge don't have any published solutions.</p>

<p>In any case, I'm attempting to have a dictionary count the number of occurrences of a certain number in the original list, before duplicates are removed.  For some reason, despite a number of variations on the theme below, I cant seem to increment the value for each of the 'keys' in the dictionary.</p>

<p>How could I code this with dictionaries?</p>

<pre><code>dv = list()
# arbitrary sequence of numbers
seq = [2,4,5,2,4,6,3,8,9,3,7,2,47,2]

# dictionary counting number of occurances
seqDic = { }

for v in seq:
    i = 1
    dv.append(v)
    for i in range(len(dv)-1):
        if dv[i] == v:
            del dv[-1]
            seqDic.setdefault(v)
            currentCount = seqDic[v]
            currentCount += 1
            print currentCount # debug
            seqDic[v]=currentCount
print "orig:", seq
print "new: ", dv
print seqDic
</code></pre>
