Python Introducing Lists Using Lists Continental

Not sure how to print a specific item from a list based on the first letter.

I am stuck... I am trying to figure out how to print specific items from a list.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
print("Continents:")
for continent in continents:
    print (continent.index[0])
#print(int continitent.index["A"]))

1 Answer

Dario Bahena
Dario Bahena
10,688 Points

You have to check for the letter that you want.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
## continents is a list
for continent in continents:
## here, continent is a single item in the list of continents. The first time it will be "Asia"
    if (continent[0] == "A"):
## Since continent is "Asia", check if the first letter is "A"
        print continent

Okay that makes sense! Thank you!