Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
19,529 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
19,529 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