"""Pluralize English nouns (stage 2)This program is part of "Dive Into Python", a free Python book forexperienced programmers. Visit http://diveintopython.org/ for thelatest version.Command line usage:$ python plural2.py nounnouns"""__author__="Mark Pilgrim (mark@diveintopython.org)"__version__="$Revision: 1.4 $"__date__="$Date: 2004/03/18 18:55:45 $"__copyright__="Copyright (c) 2004 Mark Pilgrim"__license__="Python"importredefmatch_sxz(noun):returnre.search('[sxz]$',noun)defapply_sxz(noun):returnre.sub('$','es',noun)defmatch_h(noun):returnre.search('[^aeioudgkprt]h$',noun)defapply_h(noun):returnre.sub('$','es',noun)defmatch_y(noun):returnre.search('[^aeiou]y$',noun)defapply_y(noun):returnre.sub('y$','ies',noun)defmatch_default(moun):return1defapply_default(noun):returnnoun+'s'rules=((match_sxz,apply_sxz),(match_h,apply_h),(match_y,apply_y),(match_default,apply_default))defplural(noun):formatchesRule,applyRuleinrules:ifmatchesRule(noun):returnapplyRule(noun)if__name__=='__main__':importsysifsys.argv[1:]:printplural(sys.argv[1])else:print__doc__