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

Lauren Fisk
Lauren Fisk
1,674 Points

Phython Lists - trying to "only print continents that begin with the letterย "A"."

I'm trying to figure out how to only print the continents that start with the letter "A". The hint says to access characters in a string by index, and I'm getting lost when I try to tell it to use 0, 3, 5 and 6. Am I on the right track using {}.format?

Here is the question: I'd like you to now only print continents that begin with the letterย "A". HINT: Remember that you can access characters in a string by index

continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] for continent in continents:

print("* {}".format(continents[0]))
continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents: 

    print("* {}".format(continents[]))

1 Answer

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there, Lauren Fisk! Using format is perfectly fine :smiley: However, I think you are misinterpreting the hint. Just like we can get an individual element from a list using an index, we can use the same technique to get an individual letter from a string. For example:

student_name = "Lauren"
print(student_name[0])
#  prints out "L"
print(student_name[3])
# prints out "r"

You want the same print statement you had in the previous step, but this time, you want in if statement that says if the first letter (index 0 of the string) is equal to "A", print that continent.

Hope this helps! :sparkles: