Counting duplicate characters
<p>I can't figure out why the last character in a string always gets omitted when I try the following:</p>

<pre><code>def duplicate_count(text):
    num = 0
    count = {}
    for char in text:
        print(count.items())
        if char in count.keys():
            count[char] += 1
        else:
            count [char] = 1
    for key in count:
        if count[key] == 1:
           num = 0
        else:
           num = count[key] - 1
    return (num)

char_s = 'abcde'
print (duplicate_count(char_s))
</code></pre>

<p>You only output the counts before a given character is added, so you will never see the final counts. You could move your print statement to after your <code>if</code> if you'd like to change that.</p>

<p>The other issue is that your program is only returning the duplicate count of the last entry in your dictionary. You would need to create a new dictionary, or take the highest value of num, depending on your requirements</p>

python string python-3.x