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

Aiden van der Berg
Aiden van der Berg
7,297 Points

How do I iterate over each item in the list that starts with the letter "A"?

I need a bit of help.

How do I iterate over each item in the list that starts with the letter "A"?

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

2 Answers

volhaka
volhaka
9,875 Points

you need to add condition before print (), that check if first letter of the continent == 'A' you can find first letter with index ( sting_name[0] ) or with string slicing ( string_name[:1] )

So you will execute print("* " + continent) only if first letter of the continent == 'A'

Mod Edit: Changed comment to answer so it may be voted on or marked as best answer.

Josh Keenan
Josh Keenan
20,315 Points

The comment explains the solution well.

rydavim
rydavim
18,814 Points

Thanks for pointing that out! I've changed volha kameneva 's comment to an answer.