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!

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

Sehrish Ijaz
Sehrish Ijaz
756 Points

how to retrieve continents starting with letter A?

i don't know the code in for loop to get elements with a specific letter

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
# Your code here

2 Answers

Sehrish Ijaz
Sehrish Ijaz
756 Points

tinents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ]

Your code here

for continent in continents: print("*",continent)

Steven Parker
Steven Parker
224,864 Points

You'll still need the code you did for task 1 that creates the loop, you will just add an "if" statement to control when the "print" happens.

You can access individual characters in a string by indexing, using brackets similar to working with a list. For example, since index numbers start at 0, the first character of "mystring" would be "mystring[0]".

You could then compare that to the letter "A" in a conditional expression as part of the "if" statement.

Sehrish Ijaz
Sehrish Ijaz
756 Points

Can you please send me the whole code?

Steven Parker
Steven Parker
224,864 Points

Please post the code you passed task 1 with first, then I can show you what you need to add for task 2.

Steven Parker
Steven Parker
224,864 Points

So between the "for" line and the "print", you could add:

    if continent[0] == "A": 

And be sure to adjust the indenting of the "print" line.