pull just email address from list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

pull just email address from list

Hello everyone, I'm trying to write a script that pulls only email addresses from a list and places them into a new list. My list looks like this: firstname lastname <email@email.com>, firstname lastname <email@email.com>, etc. I can't think of how to append starting after a certain character "<" and stop once a certain character is reached ">". and then continue this until the end of the list is reached. Appreciate any help Thanks, David

6th Nov 2020, 2:00 PM
David
David - avatar
2 Answers
+ 6
You can use regex import re a=["firstname lastname <email@email.com>", "firstname lastname <email@email.com>"] for i in a: print(re.findall("<(.*)>",i)) .* returns one or more occurrences of characters between < and > and brackets around it returns only that particular text instead of returning < and > as well
6th Nov 2020, 2:20 PM
Abhay
Abhay - avatar
0
Abhay thanks so much for answering! it works!
6th Nov 2020, 2:26 PM
David
David - avatar