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 trialDhruv Ghulati
1,582 PointsUnsure about why I can't use {count, } to find a sequence of unicode characters longer than count.
Hi - what am I doing wrong here? Please also explain why I am theoretically wrong so I can improve for next time :)
Thanks!!
import re
def find_words(count,string):
return re.findall(r'\w{count,}', string)
# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
2 Answers
Chase Marchione
155,055 PointsHi there,
- Inside of your function, you will want to convert count to string, so that it may be evaluated as such:
count = str(count)
- Next up is a matter of using concatenation so that the count is properly considered as a variable in your return statement, which you are very close to doing. After apostrophes and concatenation are implemented accordingly:
return re.findall(r'\w{'+ count + ',}', string)
Hope this helps.
Kenneth Love
Treehouse Guest TeacherRegex patterns are raw strings. They don't do anything special. They especially don't just read in variables and replace parts of themselves with said variables. CJ Marchione's answer is a good one.