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

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':
    print(l)
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':
    print(continent)
Anthony Crespo
seal-mask
.a{fill-rule:evenodd;}techdegree
Anthony Crespo
Python Web Development Techdegree Student 12,973 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']))