Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Regular Expressions in Python Introduction to Regular Expressions Word Length

taliarosen
taliarosen
3,529 Points

I'm getting a NoneType error even though I've identified the object as a string

The Challenge: Create a function named find_words that takes a count and a string. Return a list of all of the words in the string that are count word characters long or longer.

The error I'm getting: object of type 'NoneType' has no len()

word_length.py
import re

def find_words(count, string):
    word_list = []
    all_word_list = re.findall('/w+ ?.?,?', string)
    for word in all_word_list:
        if count <= len(str(word)):
            word_list.append(word)

# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']

1 Answer

Steven Parker
Steven Parker
231,275 Points

It's not your string that the message is referring to. The challenge is trying to determine the length of the value returned by the function, but the function doesn't currently return anything (therefore, a "None type").

Also, you need to work on the regex pattern a bit yet.