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

how can I pass the argument count into the re function?

how can I pass the argument count into the function?

import re

EXAMPLE:

>>> find_words(4, "dog, cat, baby, balloon, me")

['baby', 'balloon']

def find_words(count, str1): print( re.findall(r'\w{count,}', str1))

find_words(4, "dog, cat, baby, balloon, me")

word_length.py
import re

# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']

def find_words(count, str1):
  print( re.findall(r'\w{count,}', str1))


find_words(4, "dog, cat, baby, balloon, me")

1 Answer

Steven Parker
Steven Parker
231,248 Points

Here's a few hints:

  • just define the function, don't call it (the challenge does that itself)
  • remember to return the result, not print it
  • using the word "count" in the re string won't work, but building the string using the variable will
  • remember to convert the number into a string before concatenating with other strings

I'll bet you can get it now, but if you're still stuck...   <button' onclick='$("#spoiler").slideDown("slow");$(this).remove()'>Press to Reveal Spoiler</button> <div id='spoiler' style='display:none'>

:warning: SPOILER ALERT

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

</div>

Thank you Steven, it works as expected. It's a good idea to use str(count) to return it to raw string. :)