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

what combination of symbols should be used to escape words with numbers in them. Passing a count returns nothing oddly

A bit confused with this question. I've hard coded numbers to pass as a count but the variable I pass continuously returns no result. Any hints would be helpful :)

word_length.py
import re

# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
def find_words(*args):
    cnt,string = args
    return re.findall(r'(\w{cnt,})',string)

2 Answers

Josh Keenan
Josh Keenan
20,315 Points

So I will post my solution and explain it.

def find_words(count, string):
    return re.findall(r'(\w{' + str(count) + ',})', string)

Now the count parameter is going to be an integer, I need to include it in the regex and I can't find a way to format it in there as the curly braces seem to be used for something else at this point. So KISS, keep it simple stupid. String concatenation is an easy way to get the right value in there, there is no need to overcomplicate things and this way it works. Sorry I will explain better after I have had my coffee

Josh Keenan
Josh Keenan
20,315 Points

But basically, a lot of the time when you find yourself working on more and more complex projects, you want to use more and more complex skills from your skillset. However oftentimes the most applicable, useful, and easy choice will be what you learned long ago and is something you consider basic, try not to overcomplicate things and keep it simpler.

Wow can't believe that was all I needed. Thank you Josh