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

Having Trouble with Printing Items in a List that Only Begin With the Letter "A"

Having trouble trying to figure out how to print out only the continents that begin with the letter "A". I've been researching for a bit and trying different things I've found but at this point I'm kinda just grasping at straws. I hope someone in the community may be able to help or maybe just point me in the right direction.

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

4 Answers

Madushan Perera
Madushan Perera
7,624 Points

Hello Victor, Try this one. I think you need to use the double equation operator "==" in the condition. Hope this helps you :)

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]

for item in continents:
    if (item[0] == "A"):
        print("* " + item)

Everything's OK, you're just missing a small thing. Check out the second example:

https://docs.python.org/3/tutorial/controlflow.html#for-statements

Or you can also use the "is" keyword.

Madushan Perera
Madushan Perera
7,624 Points

Yes, We can use "is" keyword too

This is the answer. I finally figured it out and passed the challenge.

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