+2 votes
in Programming Languages by (71.8k points)

I have a list of substrings e.g. vv=['Generating train and test indices for 5-fold validation', 'Performing fold number', 'Train the classifier', 'Test the classifier',' Number of elements in metavisit_suicide_prob']

I need to remove all the lines from a file where the line has any of these substrings. e.g. if a line is 'Performing fold number 4', it should be removed. How to do this?

1 Answer

+1 vote
by (350k points)
selected by
 
Best answer

You can use any function to perform this task. Check the following example.

>>> vv=['Generating train and test indices for 5-fold validation', 'Performing fold number', 'Train the classifier', 'Test the classifier',' Number of elements in metavisit_suicide_prob']

>>> w='Performing fold number 4'

>>> any(v in w for v in vv)

True 


...