Python altering list item in iteration
<p>I am trying to get this python code to get rid of punctuation marks associated with words and count the unique words. For some reason it's still counting both "hello." and "hello". Any help would be most appreciated. </p>

<pre><code>def word_distribution(words):
            word_dict = {}
            words = words.lower()
            words = words.split()
            for word in words:
                if ord('a') &lt;= ord(word[-1]) &lt;= ord('z'):
                    pass
                elif ord('A') &lt;= ord(word[-1]) &lt;= ord('Z'):
                    pass
                else: 
                    word[:-1]
            word_dict = {word:words.count(word)+1 for word in set(words)}
            return(word_dict)
</code></pre>

<p>I don't know why you're adding 1 to count.</p>

<pre><code>def word_distribution(words):
        word_dict = {}
        words = words.lower().split()
        for word in words:
            if ord('a') &lt;= ord(word[-1]) &lt;= ord('z'):
                pass
            elif ord('A') &lt;= ord(word[-1]) &lt;= ord('Z'):
                pass
        word_dict = {word:words.count(word) for word in set(words)}
        return(word_dict)
</code></pre>

<p>{'hello': 2, 'my': 1, 'name': 1, 'is': 1}</p>

<p>Edit:</p>

<p>as brianpck, points out:</p>

<pre><code>def word_distribution(words):
        word_dict = {}
        words = words.lower().split()
        word_dict = {word:words.count(word) for word in set(words)}
        return(word_dict)
</code></pre>

<p>also will give the same result.</p>

python