Python Introducing Lists Using Lists Continental

Adam Franklin
Adam Franklin
1,261 Points

I don't know how to access my index with the first letter of a string. Any help?

What is the formula to access a strings first letter and print out all those items with the same letter in an index?

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

1 Answer

Haisam Elkewidy
Haisam Elkewidy
26,987 Points

try this:

for continent in continents: if continent[:1] == 'A' print("* " + continent)

Haisam Elkewidy
Haisam Elkewidy
26,987 Points

an explanation, so this [:1] means that you will get up to the first character of the string.

Adam Franklin
Adam Franklin
1,261 Points

Thank you. This worked. I had to add : after 'A'