delete a specific element from list python code example
Example 1: remove object from array python
my_list = [1,2,4,6,7]
del my_list[1]
print my_list
my_list.remove(4)
print my_list
my_list.pop(2)
Example 2: how to delete a particular element from a list in python
animals = ['cat', 'dog', 'dog', 'guinea pig', 'dog']
animals.remove('dog')
print('Updated animals list: ', animals)
Example 3: python how to remove elements from a list
my_list.remove(element)
animals = ['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']
animals.remove('rabbit')
print(animals)
--> ['cat', 'dog', 'guinea pig', 'rabbit']
animals = list(set['cat', 'dog', 'rabbit', 'guinea pig', 'rabbit']))
animals.remove('rabbit')
print(animals)
--> ['cat', 'dog', 'guinea pig']
Example 4: remove element from list python
animals = ['cat', 'dog', 'rabbit', 'guinea pig']
animals.remove('rabbit')
print('Updated animals list: ', animals)
Example 5: delete item from list
listname.remove(element)