Python Python Collections (2016, retired 2019) Lists Removing items from a list

Great! Now use .remove() and/or del to remove the string, the boolean, and the list from inside of messy_list. When you'

i am getting the error message that Task 1 is not passing anymore. Please help

lists.py
messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
messy_list.pop(3) and messy_list.insert(0,1)
messy_list.remove("a", False, [1, 2, 3] )

3 Answers

Steve Hunter
MOD
Steve Hunter
Treehouse Moderator 56,149 Points

Hi there,

I don't think you can pass multiple parameters to remove. I used three lines to remove each item in turn.

The error you are getting is unhelpful but if task 1 did pass, it should still. Sometimes these challenges throw up messages likes that, though.

For task one, I popped the element within the insert method so it popped straight off, then back on again.

messy_list.insert(0, messy_list.pop(3))
messy_list.remove("a")
messy_list.remove(False)
messy_list.remove([1, 2, 3])

I hope that helps.

Steve.

jopapadaki
jopapadaki
7,280 Points

Yes, Steve is right, I tried for task two, combinations of del & remove * for the appropriate usage* but it didn't take it...Had to change to one type only.

adam n
adam n
57,278 Points

.remove() can only remove one thing at a time.

Please mark my response as the 'best answer' if it helps you out!

Steve Hunter
Steve Hunter
Treehouse Moderator 56,149 Points

Should remove not work for the list, then? I got through the challenge with remove([1, 2, 3]) - do you think that's incorrect? I'd be interested to know your view on this.

Steve.

still not working. here is the corrections i have done:

messy_list = ["a", 2, 3, 1, False, [1, 2, 3]]

# Your code goes below here
messy_list.pop(3) and messy_list.insert(0,1)
messy_list.remove("a")
messy_list.remove(False)
del messy_list(5)
Steve Hunter
Steve Hunter
Treehouse Moderator 56,149 Points

I think del takes the element number within square brackets? But think about the element number - you've removed a couple so there is no element 5 when you reach that line of code.

Steve.

adam n
adam n
57,278 Points

Steve Hunter You're right. :sweat_smile: I must've went wrong somewhere.