# -*- coding: utf-8 -*- # How many presidents used a middle initial? import re prezfile = open("presidents.txt",'r') pattern = " [A-Z][.]* " i=0 m=0 for line in prezfile: i += 1 if re.search(pattern, line): print "President %s" % line.strip() m += 1 print "%s of %s presidents used a middle initial in their name." % (m, i) prezfile.close()