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 trial

Python Introducing Lists Using Lists Continental

christopher Junkins
christopher Junkins
1,357 Points

Getting right output for indexing but not able to pass the question

I'm getting the right output but guessing its the not way they want. I guess they want me to use the continent[0,3,5,6] but not sure how to get a whole item from a list added and not just the first letter of the string.

continents.py
continents = [
    'Asia',
    'South America',
    'North America',
    'Africa',
    'Europe',
    'Antarctica',
    'Australia',
]
for continent in continents:
    if continent[0] == "A":
        print("*" + continent)
christopher Junkins
christopher Junkins
1,357 Points

I just passed it. it wanted to see the space after the * and before the " to make the output not looked squished.

Thanks

If someone can give me the right procedure to pull an item from the list that would be great. for example: I wanted to list Asia and Africa, what would I use because using print(continents[0,3] will just output the first and 4th letter from every item.

1 Answer

James Joseph
James Joseph
4,885 Points

If you want to remove an item from one list and put it in the other you can use pop.

separate = [continents.pop(0), continents.pop(2)] 

Notice that I did 2 and not 3 on the second one. This is because it iterates through each one after each other. After I've poped out Asia, Africa would then take it's place in the index of 2.

More information on pop and other data structures: https://docs.python.org/3/tutorial/datastructures.html