I'm trying to weed out strings that contains "msi"
using regular expressions and a list comprehension. However, when I print the list, strings that contain "msi"
are still in the list. What exactly would the error be? This is my code:
spam_list = [l for l in spam_list if not re.match("msi", l)]
re.match()
matches from the beginning of the string. Use re.search()
, or even better, in
.
L = [l for l in L if "msi" not in l]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With