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 trialBrent Capuano
949 PointsI do not know where to begin with this one at all
I thought that "pop"'ing these off the list was the correct answer but alas it is not. Can someone point me in the right direction here?
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
pop (1)
pop (2)
pop (4)
print("continents:")
for continent in continents:
print("* " + continent)
3 Answers
Kevin Esther
8,551 PointsHi Brent,
I find breaking the for loop down helps my understanding.
I would suggest using the type function this as helps to know what type of variable you are dealing with so then you can check the python documentation to understand what methods and attributes you can work with.
for example print(type(continent)) and print(type(continents))
You will see that one is a string and the other is a list. Both of these can be accessed by indexing.
If you use the below after the code it give a better idea of whats going on.
Remember that the list is being filtered so easy to get confused by thinking your only dealing with list of 4 continents.
print(continent[0])
print(continents[0])
print(continents)
print(continents[6][0:4])
I really like the work spaces for trying and breaking code. Plus a lot of oh whats going on then there is always yes I get it moments.
Duc Bui
14,546 Pointscontinents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
print("* " + continent)
Kevin Esther
8,551 PointsHi Brent,
The pop method is really useful for processing a list till it is empty as each time you use the method it removes the item from the list.
For example I use this method when processing files in a directory and then check if the list is empty at the end.
This is how I passed the challenge on printing only the countries starting with A.
I used startwith() method however you could use indexing as shown in the course.
I also changed the continent to lower case before processing so I my equality check is lower case == lower case
continents = [
'Asia',
'South America',
'North America',
'Africa',
'Europe',
'Antarctica',
'Australia',
]
for continent in continents:
continent = continent.lower()
if continent.startswith('a'):
print("* " + continent.upper())
Brent Capuano
949 PointsI was unaware of the startswith() code. do you know how I would do this with the indexing?