Python Introducing Lists Using Lists Continental

Friedrich Dalman
Friedrich Dalman
1,502 Points

How do you choose items from the list based on the first letter of the string?

How do you choose items from the list based on the first letter of the string being "A" and print them out?

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents:
    print(continents[0], continents[3], continents[5], continents[6]zz

1 Answer

rydavim
MOD
rydavim
Treehouse Moderator 17,951 Points

You'll want to use an if statement before printing each item to check if it starts with an A. W3Schools has a good reference page for that here.

Here's a bit of pseudo code to get you started.

for continent in continents:
    # if the first character == A:
    # print the continent

If you still feel stuck, let me know and we can walk through a solution.