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

Jose Ramirez
Jose Ramirez
9,946 Points

to print out values from the continents.py index that start with the letter a

How to select the index with the letter A in the continents

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

2 Answers

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jose;

As the hint in the challenge suggests, you can use an index to check for values of strings. With that in mind, you could add in if statement to your for loop to check if the name starts with "A". Something like, using your syntax:

if x[0] == "A":

Post back if you're still stuck.

Ken

Jose, thank you for the specific title and question. It made it easy to search the forum and find someone with a similar problem as me.

Ken, thank you for the clear and concise answer. I had the if statement down, but I had over-complicated my code by adding .lower to the variable, causing it to throw a SyntaxError. Seeing your example got me to simplify (and get it running!)

Jose Ramirez
Jose Ramirez
9,946 Points

HI Ken. That works great. Thank you for your support.

Jose