python remove one element from list code example
Example 1: delete element of a list from another list python
l1 = ["a", "b", "c", "d", "e", "f"]
l2 = ["b", "c", "e"]
l1 = [elt for elt in l1 if elt not in l2]
Example 2: 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)
Example 3: python list remove item by value
l = ['Alice', 'Bob', 'Charlie', 'Bob', 'Dave']
print(l)
l.remove('Alice')
print(l)
Example 4: pytho. how to remove from a list
names = ['Boris', 'Steve', 'Phil', 'Archie']
names.pop(0)
names.remove('Steve')