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

David Sanchez
David Sanchez
623 Points

Lists Indexing - Printing certain words beginning with a specific letter

Please help with the solving the programming challenge. I'm trying to print the continents that begin with the letter A only.

I've already reviewed the section on lists multiple times and I don't believe the instructor covers this.

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

2 Answers

You have to check that first letter of each continent is "A" or not. If it is then only you have to print it

Solution

for continent in continents:
    if continent[0] == "A":
        print("*", continent)
David Sanchez
David Sanchez
623 Points

Thank you. This worked.

Josh Keenan
Josh Keenan
19,652 Points

It has been covered, you just need to add together a few things you have learned for this challenge.

You need to access the first letter of each string, and IF it is 'A', then you want to print it.

Hope this helps.