Q: list of functions not work as intended in python 3 This is from Dive into Python:
it has 2 parts:
1st part: a file called plural-rules.txt:
'[sxz]$'    '$'  'es'
'[^aeioudgkprt]h$'   '$'     'es'   
'[^aeiou]y$'    'y$'     'ies'
'$'  '$'     's'

second is a.py:
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)
rules=[] 
with open('plural-rules.txt') as pattern_file:
    for line in pattern_file:
        pattern,search, replace=line.split(None, 3)       
        #print(pattern, search, replace)
        #print(line,end='')
        rules.append(build_match_and_apply_functions(pattern, search, replace))
def plural(word):
    for matches, plurals in rules:
        if matches(word):
            return plurals(word)
print(rules[2][1]('shobby'))   ---------------------1
print("shobby's plural is", plural('shobby'))----------------------2

1 print out: shobby
2 print out: shobby's plural is None

A: You need to remove the 's that surround your tokens. Like this:
rules.append(build_match_and_apply_functions(pattern.strip("'"), search.strip("'"), replace.strip("'")))

Or build your input file like this:
[sxz]$            $   es
[^aeioudgkprt]h$  $   es   
[^aeiou]y$        y$  ies
$                 $   s

