I am working on some Python homework and somehow the .remove() function does not work properly and I can't explain why.
Input:
['', '', 'Age,Gender,Weight (kg),Height (cm)', '28,Female,58,168', '33,Male,,188', '', '', '', '', '21, Male, 95, 198']
My code:
for l in first:
if str(l) == "":
first.remove(l)
print(first)
Output:
['Age,Gender,Weight (kg),Height (cm)', '28,Female,58,168', '33,Male,,188', '', '', '', '21, Male, 95, 198']
As you can see, the empty strings in the front get removed as intended but the ones later on don't. How do I properly clean the list by using "basic" Python syntax?