Skip to content

Instantly share code, notes, and snippets.

@Natim
Created August 10, 2012 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natim/3318317 to your computer and use it in GitHub Desktop.
Save Natim/3318317 to your computer and use it in GitHub Desktop.
Extract email from a file, make them unique and sort them.
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