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

The challenge raised an error: "Didn't get the right output. Got 4 items. Should have gotten 4." ???

I tested my code in IDLE. It yields the same results when fed the sample data provided in the comments. It also accurately processes different inputs. I am not sure what's wrong with my code. Any hints or suggestions on how to make it work right would be greatly appreciated.

word_length.py
import re

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

def find_words(count, words):
    matches = []
    word_list = words.split(',')
    for each_word in word_list:
        if len(each_word.strip()) >= count:
            matches.append(each_word)

    return matches

2 Answers

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

I've made that error message a bit more explicit. You need to be using re.findall() and not just splitting the string on commas.

Y B
Y B
14,136 Points

I'm guessing because you didn't use regular expression to complete the challenge and it probably checks for that.