One of the things that you can do with lists is deleted elements that are already there.
Lists are mutable so you can add, edit, or delete elements from them.
Let us see how we can delete one element from a list.
Let us say that we have the following list:
my_list = ["a", "b", "c", "d"]
Now let us say that we want to delete element b
in it. To do that, we can use remove()
method which is going to remove the first instance of that character inside the list:
my_list.remove("b") print(my_list) # ['a', 'c', 'd']
We can also delete elements from lists using del
method and specifying the index of the element:
my_list = ["a", "b", "c", "d"] del my_list[1] print(my_list) # ['a', 'c', 'd']
That’s basically it.
I hope you find this useful.