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

Ryan Aves
Ryan Aves
2,203 Points

Hi all, Do you know why this version of code won't work for showing the continents beginning with "A"?

I tried creating a new list that only pulls "A" continents, using indexed values from the original continents list. That's still returning errors for some reason.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here


continents = continents[0,3,5,6]

print("Continents:")
for continent in continents:
  print("* " + continent) 

1 Answer

Steven Parker
Steven Parker
229,644 Points

You can't select multiple values from a list that way. But you don't want to modify the list anyway.

Just use an "if" statement so that the "print" only runs when the item begins with "A". The conditional expression can isolate the first letter of a word by using indexing with a value of 0.

Ryan Aves
Ryan Aves
2,203 Points

Gotcha, would this work as the "if" statement?

if continents[0] = "A":

print("Continents:") for continent in continents: print("* " + continent)

Steven Parker
Steven Parker
229,644 Points

Almost. A single "=" is an assignment operator. The comparison operator is "==".

Also, the "if" statement will need to be placed between the "for" and the "print" lines.