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

Can someone please help me with the continental task?

In here there is a list of continents and i have to print only the ones that start with the letter A, how do I do that, I already tried to look on forums and in the past videos but it only shows a single string not in a list, the same code would recognize the first word of a list and not the first letter.

1 Answer

Steven Parker
Steven Parker
231,269 Points

You can index a string (using brackets) to get a specific character from it, so to test if the first letter of a string stored in a variable named "word", you can do this:

    if word[0] == "A":
        # print here

And how do I index the first letter of a string in a list of more strings, because I only can get to index the first word in the list.

Steven Parker
Steven Parker
231,269 Points

Using the loop that you wrote for task 1, where you pick out each name from the big list and print it. For task 2 you just need to add the test to limit which ones are printed.