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

how can i finish this thing

filters.py

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

2 Answers

Steven Parker
Steven Parker
210,837 Points

The instructions are: Create a variable named y_words that uses a list comprehension to only contain the words from words that start with the letter "y".

It doesn't look like you've started yet, but some things you know need doing:

  • you need a variable name "y_words"
  • the variable will be assigned from a list comprehension
  • list comprehensions have brackets around them
  • part of a list comprehension will be similar to a loop
  • another part will be a conditional test
  • the condition needs to check the first letter of each word

Give it a try and if you still have trouble, show your code so far.

Amy Mou
Amy Mou
8,920 Points

Hi, you can check the first item on each string if it equals to 'y'

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