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

Hey can someone please explain to me why this does not work and how it would work?

I tried this code

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

1 Answer

Not sure what you have there:

  • You are using assignment operators in an if statement that don't make sense
  • i in your for in loop is a string but you try to use it as an index in continents[i][0]
  • You need to indent your print statement to be the code executed by your if statement

This would work

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

In the code above i is each continent name and i[0] is the first character in the name. The comparison operator == is used to compare the character to "A" and if true print the bulleted name.