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 = ['[email protected]', '[email protected]', '[email protected]', '[email protected]']
emails = [e for e in emails if pattern.search(e) == None]
# resulting list: ['[email protected]', '[email protected]']
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.
[email protected]and[email protected]. Is that what you want?.is a special character, so it will also excludebob@bocom, sinceb.commatchesbocom. Is that also what you want?is Nonereads better than== None. Also it's a bit more efficient sinceiscannot be overloaded and the interpreter can just do a pointer comparison.