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 trialRabih Atallah
3,405 Pointswrong script
Please why is my regex script wrong. Im trying to return a list of words of 'nb characters' each from the string strg
import re
# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
def find_words(nb, strg):
return re.findall(r'\w{nb,}', strg)
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsIn your regex string "nb"
is a two character string, not a variable. Try this as your regex string:
r'\w{{{0},}}'.format(nb)
Since format()
uses curly braces as field markers, you use double-curlies {{
and }}
to escape them. {0}
is the field replaced by format()
Rabih Atallah
3,405 PointsRabih Atallah
3,405 PointsThanks again! that was really helpful...