lists --> tuples in plural*.py examples and accompanying text

This commit is contained in:
Mark Pilgrim
2009-07-08 16:56:11 -04:00
parent 75a87e9865
commit 84fb68a1c4
3 changed files with 31 additions and 31 deletions
+5 -5
View File
@@ -31,11 +31,11 @@ def match_default(noun):
def apply_default(noun):
return noun + 's'
rules = [[match_sxz, apply_sxz],
[match_h, apply_h],
[match_y, apply_y],
[match_default, apply_default]
]
rules = ((match_sxz, apply_sxz),
(match_h, apply_h),
(match_y, apply_y),
(match_default, apply_default)
)
def plural(noun):
for matches_rule, apply_rule in rules:
+7 -7
View File
@@ -12,15 +12,15 @@ def build_match_and_apply_functions(pattern, search, replace):
return re.search(pattern, word)
def apply_rule(word):
return re.sub(search, replace, word)
return [matches_rule, apply_rule]
return (matches_rule, apply_rule)
patterns = \
[
['[sxz]$', '$', 'es'],
['[^aeioudgkprt]h$', '$', 'es'],
['(qu|[^aeiou])y$', 'y$', 'ies'],
['$', '$', 's']
]
(
('[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]