Brent Capuano949 Points
I 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)
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) print(continents) print(continents) print(continents[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 Bui14,546 Points
continents = [ 'Asia', 'South America', 'North America', 'Africa', 'Europe', 'Antarctica', 'Australia', ] for continent in continents: print("* " + continent)
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())