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 trialJose Ramirez
9,946 Pointsto 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 = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
# Your code here
print("Continents")
for x in continents:
print("* " + x)
2 Answers
Ken Alger
Treehouse TeacherJose;
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 Ramirez
9,946 PointsHI Ken. That works great. Thank you for your support.
Jose
Michael Russell
Courses Plus Student 8,550 PointsMichael Russell
Courses Plus Student 8,550 PointsJose, 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!)