Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Introducing Lists Using Lists Continental

Victor Curtis Jr
Victor Curtis Jr
5,012 Points

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
6,261 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
6,261 Points

Yes, We can use "is" keyword too

Victor Curtis Jr
Victor Curtis Jr
5,012 Points

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)