plural3.py
来自「Dive into Python 中文版」· Python 代码 · 共 51 行
PY
51 行
"""Pluralize English nouns (stage 3)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 plural3.py nounnouns"""__author__ = "Mark Pilgrim (mark@diveintopython.org)"__version__ = "$Revision: 1.3 $"__date__ = "$Date: 2004/03/18 16:43:37 $"__copyright__ = "Copyright (c) 2004 Mark Pilgrim"__license__ = "Python"import rerules = \ ( ( lambda word: re.search('[sxz]$', word), lambda word: re.sub('$', 'es', word) ), ( lambda word: re.search('[^aeioudgkprt]h$', word), lambda word: re.sub('$', 'es', word) ), ( lambda word: re.search('[^aeiou]y$', word), lambda word: re.sub('y$', 'ies', word) ), ( lambda word: re.search('$', word), lambda word: re.sub('$', 's', word) ) ) 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 + =
减小字号Ctrl + -
显示快捷键?