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 trialDezhi Zhu
2,662 PointsPlease help me! I am so confused
Create a function named find_words that takes a count and a string. Return a list of all of the words in the string that are count word characters long or longer.
import re
# EXAMPLE:
# >>> find_words(4, "dog, cat, baby, balloon, me")
# ['baby', 'balloon']
def find_words(num,string):
a = re.findall('\w{int(num),}',string)
return(a)
1 Answer
Steven Parker
231,269 PointsHere's a couple of hints:
- if you put the word "num" inside a string (with or without "int()" around it), it does not represent a value
- you can convert a number to a string and then use concatenation to join it with other strings
Dezhi Zhu
2,662 PointsDezhi Zhu
2,662 PointsHi Steven Thanks so much for help. There is one more thing I am quite confused.
a = re.findall('\w{{},}'.format(num),string)
Why this still not work? Where and how should I put curly bracket?
Steven Parker
231,269 PointsSteven Parker
231,269 PointsWhen using .format, if you need to include a brace character in the literal text, it can be escaped by doubling: {{ and }}.