#! /usr/bin/python """ reads text from standard input and outputs unique email addresses it finds, one to a line. """ import re from sys import stdin # found is the set of email addresses e've found so far, initially the # empty set found = set() # this pattern approximates a legal email address pat = re.compile(r'[-\w][-.\w]*@[-\w][-\w.]+[a-zA-Z]{2,4}') for line in stdin: for address in pat.findall(line): # the add() method adds an element to a set object found.add(address) # sorted() is a builtin function that takes an iterator and returns a # sorts list of its elements for address in sorted(found): print address