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 trialVictor Curtis Jr
5,268 PointsHaving Trouble with Printing Items in a List that Only Begin With the Letter "A"
Having trouble trying to figure out how to print out only the continents that begin with the letter "A". I've been researching for a bit and trying different things I've found but at this point I'm kinda just grasping at straws. I hope someone in the community may be able to help or maybe just point me in the right direction.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
if (continent[0] = "A"):
print("* " + continent)
4 Answers
Madushan Perera
7,624 PointsHello Victor, Try this one. I think you need to use the double equation operator "==" in the condition. Hope this helps you :)
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for item in continents:
if (item[0] == "A"):
print("* " + item)
Kristjan Vingel
7,992 PointsEverything's OK, you're just missing a small thing. Check out the second example:
https://docs.python.org/3/tutorial/controlflow.html#for-statements
Kristjan Vingel
7,992 PointsOr you can also use the "is" keyword.
Madushan Perera
7,624 PointsYes, We can use "is" keyword too
Victor Curtis Jr
5,268 PointsThis is the answer. I finally figured it out and passed the challenge.
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
if (continent[0] == "A"):
print("* " + continent)