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

Anders Axelsen
Anders Axelsen
3,471 Points

How do I make an if-statement of which the condition is a string in the list, continents, starting with the letter 'A'?

Here is my attempt on finding a as the first letter of the list item. #fail

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

Do you have specific advice? Please share.

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

You're very close. The way to check the first letter being "A" is slightly simpler that you had.

continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here
print("Continents:")
for continent in continents:
    if continent[0] == "A":
        print("* " + continent)
Anders Axelsen
Anders Axelsen
3,471 Points

You're right! How satisfying to see the content of the video lesson being truly relevant to the task.

Anders Axelsen
Anders Axelsen
3,471 Points

I found out to index the individual continent as such:

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