?? plural3.py
字號:
"""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__
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -