Counting how many words are over a certain limit in a string Python
<p>Thank you all for help on previous part. I have now finished that.
However changing title slightly and rewording question I now say that this is my code.</p>

<pre><code>s = raw_input("Enter your text: ")

longestWord = max(s.split(), key=len)

k = list(s)

count = len(k)

wordsOver = []

over = count - 140

def numLen(s, n):
    return sum(1 for x in s.split() if len(x) &gt;= n)
    for x in s.split():
        if len(x) &gt;= n:
            wordsOver.insert(0, x)

val = numLen(s, 7)

if count &gt; 140:
    print ("Sorry, that is more than 140 characters.")
    print ("You had a total of " + str(count) + " characters.")
    print ("That's " + str(over) + " over the max allowed.")
    print ("You're longest word was, " + longestWord)
    print ("There are " + str(val) + " words over 7 characters.")
    print ("They were:")
    print (wordsOver)
    print ("You may want to consider changing them for shorter words.")
else:
    print ("That's short enough!")
</code></pre>

<p>So now what I'm looking for is why the displaying of the words that are over isn't working, why and how to fix it. BTW for a little help it's the wordsOver bit that's broken</p>

<p>isalpha() doesn't return true for whitespace.</p>

<p>Additionally, there are a whole slew of better ways to do this.  You should look at the Counter class in collections.  It's a dictionary that will provide you with what you need.</p>

python python-2.7