1myList.remove(item) # Removes first instance of "item" from myList
2myList.pop(i) # Removes and returns item at myList[i]
1s = {0, 1, 2}
2s.discard(0)
3print(s)
4{1, 2}
5
6# discard() does not throw an exception if element not found
7s.discard(0)
8
9# remove() will throw
10s.remove(0)
11Traceback (most recent call last):
12 File "<stdin>", line 1, in <module>
13KeyError: 0
1a = [10, 20, 30, 20]
2a.remove(20)
3# a = [10, 30, 20]
4# removed first instance of argument
1# the list.remove(object) method takes one argument
2# the object or element value you want to remove from the list
3# it removes the first coccurence from the list
4
5generic_list = [1, 2, 2, 2, 3, 3, 4, 5, 5, 5, 6, 8, 8, 8]
6
7generic_list.remove(1)
8
9# The Generic list will now be:
10# [2, 2, 2, 3, 3, 4, 5, 5, 5, 6, 8, 8, 8]
11
12