I have a list of strings and I want to extract the next word after a specific keyword in each string.
When I am using the lambda function to iterate over the list, I am getting the whole strings instead of just the next word after the keyword:
import re
s = ["The job ABS is scheduled by Bob.", "The job BFG is scheduled by Alice."]
user = filter(lambda i:re.search('(?<=The job )(\w+)',i),s)
print(*user)
output: The job ABS is scheduled by Bob. The job BFG is scheduled by Alice.
but, when I am trying the same code for a single string, it is giving the correct output:
import re
s = "The job ABS is scheduled by Bob."
user = re.search('(?<=The job )(\w+)',s)
print(user.group())
output: ABS
How can I get output like (ABS, BFG) from the first code snippet?