Im Stuck on challenge Task 2 of 2...
I need to list every continent that begins with A but i am not sure how to do this.
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] for continent in continents: print("* " + continent)
Hakim Rachidi37,409 Points
To achive this you have multiple options
for continent in continents: if continent == "A": print("* " + continent)
As you can index strings
continent is the first character of continent.
for continent in filter(lambda c: c == "A", continents): print("* " + continent)
Both work fine, I tend to use the
if in the loop (with
filter() you are first filtering for all continents that start with 'a' and then loop over them), as it looks cleaner and is more performant;