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

Assistance with Introducing Lists Challenge Task 2.

Hello Community,

I have found that I am not understanding how to use the str function and index in order to list only the continents that start with "A". I want to know what I am doing wrong so that I can better understand and correct my error. Thank you!

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

print(str(index), "A", str(continent))
for continent in continents:
  if continent[0] == "A"
   print("* " + continent)

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,454 Points

In Python, a str can be tested like a read-only list (known as immutable) where each letter can be accessed by its position. Like a list, the first letter is at index 0.

As an example:

SyntaxError: invalid character in identifier
>>> name =  'Bermuda'
>>> name[0]
B
>>> if name[0] == 'B':
...     print('starts with B')
... 

starts with B

To restrict printing to only countries starting with “A”, a similar if statement could be added above the print within your for loop.

Post back if you need more help. Good luck!!!

Thank you Chris! Your answer was helpful and I finally understand what needed to be done.