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

RegEx Code Challenge: Word Length... lengths are right, but getting "Bummer".

I'm using this code:

import re

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

def find_words(count, sample):
    repeater = r'[A-Za-z]{'+str(count)+',}'
    return re.findall(repeater, sample)

which seems to return the correct list of words in the failure output.

Bummer! Didn't get the right output. Output was ['Treehouse', 'student', 'Kenneth', 'Python']. Length was 6.

What's gone wrong here?

1 Answer

Steven Parker
Steven Parker
243,318 Points

Well, it's not returning the complete list that is expected.

Apparently they consider a "word" to be a string of alphanumeric characters (not strictly alphabetic).

Yeah, you're right. "Word characters" is the term used in the challenge. Changing the [A-Za-z] to simply \w passes, so the code is changed to pass as:

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