码迷,mamicode.com
首页 > 编程语言 > 详细

python中关于闭合器的应用

时间:2019-11-01 12:37:04      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:arch   port   search   imp   ret   att   def   match   function   

import re
def build_match_and_apply_functions(pattern, search, replace):

def matches_rule(word):

return re.search(pattern, word)

def apply_rule(word):

return re.sub(search, replace, word)

return (matches_rule, apply_rule)
patterns = \
(
(‘[sxz]$‘, ‘$‘, ‘es‘),
(‘[^aeioudgkprt]h$‘, ‘$‘, ‘es‘),
(‘(qu|[^aeiou])y$‘, ‘y$‘, ‘ies‘),
(‘$‘, ‘$‘, ‘s‘)
)
rules = [build_match_and_apply_functions(pattern, search, replace)
for (pattern, search, replace) in patterns]
def plural(noun):
for matches_rule, apply_rule in rules:
if matches_rule(noun):
return print(apply_rule(noun))

python中关于闭合器的应用

标签:arch   port   search   imp   ret   att   def   match   function   

原文地址:https://www.cnblogs.com/yuanmq/p/11776116.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!