Example 1: python remove element from list
myList.remove(item) # Removes first instance of "item" from myList
myList.pop(i) # Removes and returns item at myList[i]
Example 2: delete element list python
list.remove(element)
Example 3: remove element from list
>>> a = [0, 2, 3, 2]
>>> a.remove(2)
>>> a
[0, 3, 2]
Example 4: remove value from python list by value
>>> a = ['a', 'b', 'c', 'd']
>>> a.remove('b')
>>> print a
['a', 'c', 'd']
Example 5: how to delete an item from a list python
myList = ['Item', 'Item', 'Delete Me!', 'Item']
del myList[2] # myList now equals ['Item', 'Item', 'Item']
Example 6: python remove value from list
# Below are examples of 'remove', 'del', and 'pop'
# methods of removing from a python list
""" 'remove' removes the first matching value, not a specific index: """
>>> a = [0, 2, 3, 2]
>>> a.remove(2)
>>> a
[0, 3, 2]
""" 'del' removes the item at a specific index: """
>>> a = [9, 8, 7, 6]
>>> del a[1]
>>> a
[9, 7, 6]
""" 'pop' removes the item at a specific index and returns it. """
>>> a = [4, 3, 5]
>>> a.pop(1)
3
>>> a
[4, 5]
""" Their error modes are different too: """
>>> a = [4, 5, 6]
>>> a.remove(7)
Traceback (most recent call last):
File "", line 1, in
ValueError: list.remove(x): x not in list
>>> del a[7]
Traceback (most recent call last):
File "", line 1, in
IndexError: list assignment index out of range
>>> a.pop(7)
Traceback (most recent call last):
File "", line 1, in
IndexError: pop index out of range