remove certain elements from list python code example
Example 1: python remove element from list
myList.remove(item)
myList.pop(i)
Example 2: python list .remove
a = [10, 20, 30, 20]
a.remove(20)
Example 3: remove value from python list by value
>>> a = ['a', 'b', 'c', 'd']
>>> a.remove('b')
>>> print a
['a', 'c', 'd']
Example 4: how to delete an item from a list python
myList = ['Item', 'Item', 'Delete Me!', 'Item']
del myList[2]
Example 5: remove element from list python
animals = ['cat', 'dog', 'rabbit', 'guinea pig']
animals.remove('rabbit')
print('Updated animals list: ', animals)
Example 6: remove element from list python
animals = ['cat', 'dog', 'rabbit', 'guinea pig']
animals.remove('rabbit')
print('Updated animals list: ', animals)
animals = ['cat', 'dog', 'dog', 'guinea pig', 'dog']
animals.remove('dog')
print('Updated animals list: ', animals)
animals = ['cat', 'dog', 'rabbit', 'guinea pig']
animals.remove('fish')
print('Updated animals list: ', animals)