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

Mark Nembhard
Mark Nembhard
1,387 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
20,315 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]