Created
August 10, 2012 21:49
-
-
Save Natim/3318317 to your computer and use it in GitHub Desktop.
Extract email from a file, make them unique and sort them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, sys | |
email_pattern = re.compile('([\w\-\.]+@(\w[\w\-]+\.)+[\w\-]+)') | |
email_list = [] | |
for line in sys.stdin: | |
# there are several matches per line | |
for match in email_pattern.findall(line): | |
email = match[0].lower() | |
if email not in email_list: | |
email_list.append(email) | |
email_list.sort() | |
for email in email_list: | |
print email |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment