Python Introducing Lists Using Lists Continental

James Hamer
James Hamer
586 Points

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

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)