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 Python Collections (2016, retired 2019) Lists Removing items from a list

Sondre Fjellving
Sondre Fjellving
4,700 Points

How would you solve this task?

I have been stuck with this task for 2 hours now, and I cannot grasp my head around it. For some reason I am not able to iterate through the list using a for loop.

Some suggestions would be much appreciated! Thanks in advance!

I am going to bed now, I will be back in a few hours.

Jake Kobs
Jake Kobs
9,215 Points

Like so:

messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]
#Storing the value at index 3 in popVal variable
popVal = messy_list.pop(3)
#Inserting popVal at index 0 of messy_list
messy_list.insert(0,popVal)

# Removing letter "a" from list
messy_list.remove("a")
#Deleting 3rd element from list (False)
del messy_list[3]
#Deleting 3rd element from list ([1,2,3])
del messy_list[3]

Hope this helps!

2 Answers

Sondre Fjellving
Sondre Fjellving
4,700 Points

Thanks Jake! This helped. Have a good day and happy coding, see you around! :)

Jake Kobs
Jake Kobs
9,215 Points

No worries! I took this course a while back so I had to do some googling. Google is your friend when it comes to coding.

Best wishes, Jake

Sondre Fjellving
Sondre Fjellving
4,700 Points

Yeah, it is so nice of you to help me! I will keep that in mind!