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 Functional Python Functional Workhorses Filter comprehension

Bug report

He!

I believe there is a bug in the verification of this assignment. The assignment passes with the attached code. However this code would not only pick words from words[] starting with a 'y'.

For that reason there should be a word in words[] with an 'y' in it but doesnt start with it. Such as "today".

Same goes for comprehension see second code.

filters.py
words = [
    'yellow',
    'red',
    'yesterday',
    'tomorrow',
    'zucchini',
    'eggplant',
    'year',
    'month',
    'yell',
    'yonder',
]

def check(word):
    return 'y' in word

y_words = list(filter(check, words))
filters.py
words = [
    'yellow',
    'red',
    'yesterday',
    'tomorrow',
    'zucchini',
    'eggplant',
    'year',
    'month',
    'yell',
    'yonder',
]
y_words = [word for word in words if 'y' in word]

You're right Rinze Winters. This does appear to be a bug. Seems kinda funny that it hasn't been fixed yet. :)

3 Answers

'''y_words = [word for word in words if word[0] == "y"]'''

y_words = [word for word in words if word[0] =="y"]

The letter 'y' has to be on the first place.

gustavoalvarado
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
gustavoalvarado
Python Development Techdegree Graduate 11,933 Points

Hi! Here is another option to solve the Challenge. Have a nice day!

words = [
    'yellow',
    'red',
    'yesterday',
    'tomorrow',
    'maybe',
    'zucchini',
    'eggplant',
    'year',
    'month',
    'yell',
    'yonder',
    'today',
]

y_words = [words for words in words if words.startswith('y')]