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

Luis Wenus
Luis Wenus
634 Points

Can#t find out which code to use

Trying to come up with the right code for question two.. I believe I should use if but don't know how to access all the first letters in a list... and how to make that an if statement. Please help.

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

for continent in continents_a:
    print("* " + continent)
Luis Wenus
Luis Wenus
634 Points

Sorry forgot to change my code back after I tried something. continents_a should of course be continents.

1 Answer

Alex Koumparos
seal-mask
.a{fill-rule:evenodd;}techdegree
Alex Koumparos
Python Development Techdegree Student 36,887 Points

Hi Luis,

You're already iterating through the list, so during each iteration you only need to know how to access the first character in a string. Remember that you can index into a string with square brackets, just like a list. If you need a refresher on indexing into lists, have a rewatch of Indexing.

As for putting it in an if statement, once you have the first character in the string, you can use the == operator to compare it to the letter 'A'.

Hope that helps

Alex