I have a list that contains strings. I want to drop out the ones that have specific strings using python.
For example:
my_sample_list = ["I am practicing Python", "I am practicing Java", "I am practicing SQL"]
I want to drop out the element that contains "SQL" and I will be left with:
my_new_sample_list = ["I am practicing Python", "I am practicing Java"]
How can I do that in python, please? Any help would be appreciated.
>Solution :
Iterate over the strings and check if the pattern is contained in it or not.
my_sample_list = ["I am practicing Python", "I am practicing Java", "I am practicing SQL"]
pattern = 'SQL'
my_new_sample_list = [s for s in my_sample_list if pattern not in s]