Python Introducing Lists Using Lists Continental

Tsering Choedhen
Tsering Choedhen
1,050 Points

Any suggestions how to print continents that begin with letter "A" please?

I am trying to access the string in a list. But i can't think of any. Happy to hear your help.
continents = [
    'South America',
    'North America',
# Your code here
for continent in continents:
    print("* " + continent)
while continents[0][0]

2 Answers

How about you try to use an if condition and not while. I want you to figure this out by yourself so DON'T look at the direct solution below BEFORE reading the indirect solution.

INDIRECT SOLUTION: suppose you have a list of words, and in those list of words I want you to give me words that start with an alphabet "A", so your solution would be something like;

For each word in this list of words, if the alphabet "A" is the first letter in this word, I want that word


for word in words:
    if "A" == word[0]:

The actual solution to the challenge:

since the instructor wants you to make use of indexing, let's solve using indexing

for continent in continents:

    if "A" == continent[0]:   # Made use of indexing here uisng the "if" condition

        print("* " + continent)

That's it

Tsering Choedhen
Tsering Choedhen
1,050 Points

Thank you @boi for your interesting way of making me to think for the solution.