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 trialwael ayad
3,220 PointsCreate a function named find_words that takes a count and a string. Return a list of all of the words in the string that
i don't know how to do this task can you help me
import re
# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
def find_words(count, string):
return re.findall(r'\w {count,}', string)
1 Answer
Troy Riggs
13,859 PointsRight now your passing a string to findall that includes the word count. What you want to do is convert the number that count represents to a string and then insert that into the string that you pass to find all. Break the string you pass to findall into two parts, before count and after count. Convert the value of count using the str() function and add it into the string for findall.
def find_words(count, string): return re.findall(r'\w{'+ str(count) +'}', string)