Python Introducing Lists Using Lists Continental

Mark Nembhard
Mark Nembhard
464 Points

How do you find the letter A in a string in a list?

It is the question on only printing the continents that starts with A

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents:
    If continent == "A":
        print("*", continent)

1 Answer

Josh Keenan
Josh Keenan
17,329 Points

Firstly, you need to be careful with casing.

for continent in continents:
    If continent == "A":
        print("*", continent)

That is not going to be read as the reserved word "if" but as something else entirely.

For the first part of the challenge you only need a for loop to iterate over the array and output them all bulletpointed like this:

for continent in continents:
    print("*", continent)

But for part two you aren't looking to see if the value itself is the string "A" but if the string starts with "A", remember you can access the first character of a string like a list with indexing, hope this helps!

mystring[0]