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,212 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,212 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!