Python Introducing Lists Using Lists Continental

Emily Strobl
Emily Strobl
4,585 Points

help me part 3

i tried everything to indext just the continents that begin with A but im still getting all of the continents
continents = [
    'South America',
    'North America',

print ('continents'[0])

print ('continents:')
for continent in continents:
    print('* ' + continent)

1 Answer

Cameron S
Cameron S
20,056 Points

You need to use the slice to get the first letter of each list item within a if statement to make sure the returned value is equal to 'A'. That if statements should be inside the for loop you already have.

For example:

# list of continents
>>> continents = [
...     'Asia',
...     'South America',
...     'North America',
...     'Africa',
...     'Europe',
...     'Antarctica',
...     'Australia',
... ]

>>> for continent in continents:
           # if the first index (first letter) of each item within 
           # the list is equal to "A"
...         if continent[0] == "A":
...                 print(continent)

Also note a bug within your code:

# this will return the first index of the string 'continents not the list. 
# so you would get back the letter 'c' instead of a continent from the list