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

l

l

word_length.py
import re

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

def find_words(count, string):
    return re.findall(r'', string)
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hi Sarah Ruszkowski

Your Title and body make no sense. "I" is not a proper title or question to be posted to the community. Please edit the post to contain a valid title and a valid question.

Thank you!

Jason Anders ~Treehouse Community Moderator~

2 Answers

Salam El Bsat
Salam El Bsat
2,005 Points

Hi Sarah Ruszkowski,

In the word length exercise, they asked to return a list of the words that has count number of characters or more.

first, you got it right by using re.findall(r'',string), what is missing overhere is the ingredients of the raw string.

it is a number of unicode characters or more, you can think of two representations:

  • r'\w{count,)': This is intuitive and logically correct, this only issue with it is that you embedded a variable name inside a string, so the method will not recognize it as a variable and will search for something else. However, if you write r'\w{4,}': the example will work.

  • r'\w+'*count: This checks if a unicode character occurs at least with the \w+, and then multiplies that one by count, so that it will be searching for at least that much number of characters or more! And this can be the valid solution in this case.

Hope this helps, Salam

Sorry about the craziness here. I wanted to access the forums without using fancy links. Is there a better way to do this?

Salam El Bsat
Salam El Bsat
2,005 Points

Sarah Ruszkowski, clicking on the Community tab in the top-most bar of the website takes you to the forums, then there, you can search for any question or keyword of interest.

Hope this helps, Salam