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

Adam Kroner
Adam Kroner
1,460 Points

Still not understanding...

Am I supposed to change my for variable? Am I indexing at the incorrect location? I have watched the entire course multiple times and read the wiki pages among other sources. All review questions are answered quite easily by me. However not grasping list indexing while utilizing for in much at all. I do not understand how the for variable works in general.

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

2 Answers

Steven Parker
Steven Parker
231,269 Points

The indexing seems correct, but when calling a method, (like "upper") the name must be followed by parentheses (even if no argument is being passed). But be aware that nothing converted to upper case will ever match "a".

And case conversion is "overkill" here anyway, you can compare the first character directly with "A".

Adam Kroner
Adam Kroner
1,460 Points

I still don't understand, how am I supposed to compare directly with "A". I don't even know where to begin that process, apparently. How I read the code I wrote says to go through the list and only print out the continents whose first letter [0] is "A", which is what the question is asking. I want to move on but I'm not understanding a big part of this. Hitting a dead end because explanations aren't making much sense I need an example, and the ones in the video do not make the solution for this problem clear to me.

Steven Parker
Steven Parker
231,269 Points

This is comparing with case conversion :point_right: continent[0].lower() == "a"
...and this would be comparing directly :point_right: continent[0] == "A"

Adam Kroner
Adam Kroner
1,460 Points

OMG I was forgetting the semi colon after the direct comparison, thank you! Could not understand why it kept throwing a syntax error!

You have the for loop correctly to loop through every element of the list. continent[0] refers to the first letter of that continent. When looping over the list, you are going to get, for example, A for Asia, S for South America. As a comparison, continents[0] would give you the first element of continents, which is "Asia".

You seem to be missing parenthesis to upper to call this function, i.e. continent[0].upper(). However, this is never going to be true as you are looking for an uppercase to be equal to lower case "a".