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 Introducing Lists Using Lists Continental

How do you print items from a list beginning with the letter A?

Hi, I am trying to print only the items within a list that begin with the letter A. in this instance the list is a list of continents

1 Answer

boi
boi
14,241 Points

Hey James!! how are you. So you want a code that prints every string beginning with the letter "a" or "A". First of all, I would like to recommend that try to frustrate yourself by solving a code, it gives your brain the creativity to think, that's the point of challenges. :) anyways here is my approach, I hope this helps.

alpha = "aA"
list1 = ["Antarctica","Africa","Europe","Asia","North America","South America","Australia"]
for x in list1:
  if x[0] in alpha:
    print(x)

Here is a more elaborated version :

list1 = ["Antarctica","Africa","Europe","Asia","North America","South America","Australia"]
for x in list1:
  if "A" in x:
      print(x)
  elif "a" in x:
    print(x)