Can someone explain how I made this code work? : <p>So we had a lab activity a few days ago where we had to print the number of letters in a word alphabetically. No duplicate printing of the same letter. For some reason, I got it to work by typing the condition if x[i] == x[i-1] but after coming home, I can't wrap my head on how I came up with this and how this works in the first place. Can someone explain to me how it worked? Even though it worked I want to know the logic behind that "if" condition. Thanks and good day.</p>

<pre><code>word = (sorted(str.upper(raw_input("Enter your word(s): "))))

def counts(x):
    for i in range(len(x)):
        count = 0
        for g in range(len(x)):
            if x[g] == x[i]:    count += 1
            else:   continue
        if x[i] == x[i-1]:
            continue
        else:
            print x[i],"occurs", count,"times."

counts(word)
</code></pre>
