I have a list with some dummy email address as below:
listEmails = ['[email protected]', '[email protected]', '[email protected]']
I was trying to use lambda and filter to get the list of valid email address.
let's assume [email protected] is the only invalid email address.
I used the regular expression to filter out the invalid emails using the below code.
listValid = list(filter(lambda x: x if re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]{0,3}$",x) ,listEmails))
I have been receiving a syntax error at , before listEmails)).
Generally, the lambda function takes the value after the comma(,) as the input value, so I am not sure if the lambda function is assuming x from re.match(r"^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]{0,3}$",x) as the input value.
Lambda function with if conditions are possible from the below case:
from functools import reduce
f = lambda a,b: a if (a > b) else b
reduce(f, [47,11,42,102,13])
So, I wanted to know why it isn't working in my case?
Note: Since I got an error at the lambda function itself, I haven't evaluated if the list(filter( would return the desired result.