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 trialStefan Vaziri
17,453 PointsStuck on this one...
Not doing this right and can't figure it out...
words = [
'yellow',
'red',
'yesterday',
'tomorrow',
'zucchini',
'eggplant',
'year',
'month',
'yell',
'yonder',
]
y_words = words.list(filter(y))
1 Answer
Haider Ali
Python Development Techdegree Graduate 24,728 PointsHi there Stefan. This challenge is actually asking you to create a list comprehension instead of using filter()
. If you are not familiar with comprehensions in python, you should check out the 13 minute long workshop they have in the library. Here is what your code should look like anyway:
words = [
'yellow',
'red',
'yesterday',
'tomorrow',
'zucchini',
'eggplant',
'year',
'month',
'yell',
'yonder',
]
y_words = [word for word in words if word[0] == 'y']
This list comprehension goes through each word in words
and makes a list of all the words which have an index 0 of 'y'. I hope this helped. If you have any further questions, let me know.
Thanks, Haider
Stefan Vaziri
17,453 PointsStefan Vaziri
17,453 PointsThanks Haider! Why did you do "if word[0]"? Edit: Nevermind, I got it. Thanks so much!