#!/usr/bin/python # popgrep2 - grep for abbreviations of places that say "pop" # version 2: compile the patterns import fileinput import re popstates = ["CO","ON","MI","WI","MN"] state_re = [] for state in popstates: state_re.append(re.compile(r"\b"+state+r"\b")) for line in fileinput.input(): for state in state_re: if state.search(line): print line