I would like to remove the words of each nested list that appear in the garbage
list.
List to clean:
main_list = [['CV', 'Bob', 'Jones', '20201027'], ['Resume', 'Andrea', 'Jones'], ['Claire', 'Jonson', 'CV', 'Resume', 'Format', 'Test']]
Desired output (only the names):
[['Bob', 'Jones'], ['Andrea', 'Jones'], ['Claire', 'Jonson']]
current code:
garbage = ['CV', 'Resume', 'Format', 'Person', 'Test' ]
for nested_list in main_list:
for word in nested_list:
if word in garbage or word.isdigit():
nested_list.remove(word)
print(main_list)
current output:
[['Bob', 'Jones'], ['Andrea', 'Jones'], ['Claire', 'Jonson', 'Resume', 'Test']]
This is only a representation of the actual data I am working with, it is important that the filtering is done based on this garbage
list. As you can see, in the current output, the 3rd item is not filtered correctly. Why is this and what can be done ?