?? plural2.py
字號:
"""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"import redef match_sxz(noun): return re.search('[sxz]$', noun)def apply_sxz(noun): return re.sub('$', 'es', noun)def match_h(noun): return re.search('[^aeioudgkprt]h$', noun)def apply_h(noun): return re.sub('$', 'es', noun)def match_y(noun): return re.search('[^aeiou]y$', noun) def apply_y(noun): return re.sub('y$', 'ies', noun)def match_default(moun): return 1def apply_default(noun): return noun + 's'rules = ((match_sxz, apply_sxz), (match_h, apply_h), (match_y, apply_y), (match_default, apply_default) )def plural(noun): for matchesRule, applyRule in rules: if matchesRule(noun): return applyRule(noun)if __name__ == '__main__': import sys if sys.argv[1:]: print plural(sys.argv[1]) else: print __doc__
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -