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 trialTapiwanashe Jandura
2,677 PointsI'm completely lost
How do I separate just the continents starting with A
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print("* {}".format(continent))
1 Answer
Ave Nurme
20,907 PointsHi Tapiwanashe
When I look at the challenge there's a hint -> HINT: Remember that you can access characters in a string by index Let's take the first element in the list 'continents' which is 'Asia'. 'Asia' has 4 characters: A, s, i & a. We can access these all by index. Here it is important to keep in mind that with indices we start counting from zero. So...
- A -> index 0
- s -> index 1
- i -> index 2
- a -> index 3
We can access these as follows:
- A -> index 0 -> continent[0]
- s -> index 1 -> continent[1]
- i -> index 2 -> continent[2]
- a -> index 3 -> -> continent[3]
We are asked to find all the continents which begin with the letter 'A' which means we need to check the first character so this is the character at index zero -> continent[0]
So...
for continent in continents:
if continent[0] == 'A':
print("* {}".format(continent))
Hope this helps!