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

Christopher Ruth
PLUS
Christopher Ruth
Courses Plus Student 132 Points

My Code is outputting words of length 6, but the checker is still not happy.

"Bummer: Didn't get the right output. Output was ['Treehouse', 'student', 'Kenneth', 'Python']. Length was 6."

Those words are all of length 6 or more! I'm stumped.

word_length.py
import re

def find_words(c, s):
    regex = r'[a-zA-Z]{' + str(c) + ',}'
    res = re.findall(regex, s)
    return res

2 Answers

John Lack-Wilson
John Lack-Wilson
8,181 Points

You're pretty close! The issue is in your regex. You can use \w to signify a word, rather than using a-zA-Z. Also, I don't think the r is required at the start for this challenge.

Aldo Rivadeneira
Aldo Rivadeneira
3,241 Points

I also get into this point but in a different way , but im getting the same error

import re

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

    # first i need to split the args
    # then i need to store in to the list 
    # and make a loop to apply the regex, if it matches stores in a new list
    # done
    item_list = []
    item_list = data.split(", ")
    regex = "\w" + "{" + str(count) + ",}"
    return_list = []

    for item in item_list:
        if re.findall(regex, item):
            print(item)
            # print(re.findall(regex, item))
            return_list.append(re.findall(regex, item))

    return return_list


find_words(4, "dog, cat, baby, balloon, me")