Right now I'm "removing" emails from a list by mapping a new list excluding the things I don't want. This looked like:
pattern = re.compile('b\.com')
emails = ['user@a.com', 'user@b.com', 'user@c.com', 'user@d.com']
emails = [e for e in emails if pattern.search(e) == None]
# resulting list: ['user@a.com', 'user@c.com']
However, now I need to filter out multiple domains, so I have a list of domains that need to be filtered out.
pattern_list = ['b.com', 'c.com']
Is there a way to do this still in list comprehension form or am I going to have to revert back to nested for loops?
Note: splitting the string at the @ and doing word[1] in pattern_list
won't work because c.com
needs to catch sub.c.com
as well.