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.


am Stuck

please how do i print items in a list that start with a specific "letter". here is a link to my challenge question https://teamtreehouse.com/library/introducing-lists/using-lists/continental

Let's see what your code looks like so far.

2 Answers

Rahul Saini
Rahul Saini
4,611 Points

Use this pseudo code and i am sure it will help

list = ['This","is","Just","a","code","in","python"]
for l in list:
  if l[0] == 'T':
Benjamin McKay
Benjamin McKay
Courses Plus Student 3,767 Points

Also useful to note that you can iterate through list items in any way that works well for you. Rahul uses 'l' to loop through the list, but you could say

for item in list:
  if item[0]...

or any other term that works well for you.

In your case maybe you would like something like

for continent in continents:
  if continent[0] == 'A':
Anthony Crespo
Anthony Crespo
Python Web Development Techdegree Student 12,961 Points

You can even put it all in one beautiful line.

lst = ['Carrots', 'Cabbage', 'Beans', 'Tomatoes', 'Cucumbers']
print(', '.join([item for item in lst if item[0] == 'C']))