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

Michael Pastran
Michael Pastran
4,727 Points

word_length challenge

i understand the question that is being asked, i just dont get why my code isnt passing. im making an empty list that will hold all the words in my string that a longer or have the same amount of characters as "int". then im going through the string checking for words longer than {int}. and then appending those words that fit the description. any help would be awesome. thanks

word_length.py
import re

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

def find_words(int, str):
  words = []
  search = re.findall(r'\w{int}', str)
  words.append(search)
  return words

1 Answer

Kenneth Love
STAFF
Kenneth Love
Treehouse Guest Teacher

Remember, regex are dumb so '\w{int}' literally says "look for an 'int' number of word characters". What number is 'int'? Not the variable int, literally the characters 'int'. You'll have to get your variable value into the string somehow. I'd suggest concatenation.