Removing Elements From Lists


#1

I am having trouble with this lesson, I keep getting an error that says "It looks like your list is [] instead of [3, 5]."
My code is:
n = [1, 3, 5]

Removes 1 from the list,

NOT the item at index 1

n.remove(1)

Another possible solution, will remove the item at the given index:

del(n[0])

Another possible solution will remove the item at index from the list and return it to you:

n.pop(0)
print n


#2

You seem to have 3 ways of removing things. However, you are actually removing all three items of the list per way.
Such as n.remove(1) will remove the 1 in the list.
del(n[0]) will remove the 3 (since it is not the first item at index 0 after removing 1)
n.pop(0) removes the 5 since it is the only item left and is not at index 0 after removing 1 and 3.

Just pick one of those methods. That's all.


#3

Thanks for the help!


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.