Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Regular Expressions in Python Introduction to Regular Expressions Word Length

Rabih Atallah
Rabih Atallah
3,405 Points

challenge problem

PLease how can I fix my code? help is much appreciated

import re

# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
def find_words(nb, string2):
  L = []
  for e in string2.split():
    if len(e) >= nb:
  return L

1 Answer

Chris Freeman
Chris Freeman
Treehouse Moderator 67,989 Points

First hint is some of the items in the string are adjacent to a comma, so splitting with the default split() leaves words like "match,"

Second hint is this is an re challenge so you'll likely need to use an 're.search' or 're.match' to find the correct solution to look for words of nb or longer actual characters: r'\w'*6

Bonus, first string2.split() isn't assigned to a variable so it's output is thrown away. The line could be deleted.

Rabih Atallah
Rabih Atallah
3,405 Points

Thank you again Chris! It was very helpful I really appreciate it