I'm learning python and I wanted to create some code which would take a list of lists, check if each row had a particular value for a given index number and if it did, delete the entire row. Now I intuitively decided to use del
to delete the rows, but when I printed out the list with the removed values, I got the same list back. I added a counter to check if there were any rows which had the value to be removed and they did indeed exist. The problem I have is illustrated by the following code:
test_list=[1,2,3,4,5]
for element in test_list:
if element == 1:
del element
print (test_list)
Output
[1,2,3,4,5]
What is the function of del, if not to delete the element here?