language: Python (python 2.7.3)
date: 317 days 13 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
from difflib import get_close_matches
 
def get_target_match(target, targets):
    '''
    Approximates a match for a target from a sequence of targets,
    if a match exists.
    '''
 
    matches = get_close_matches(target, targets)
    print target, targets
    print matches
    return matches and matches[0] or None
 
target = 'z'
targets = ['Joe', 'Bob', 'zombie', 'Susan', 'kobold', 'Bill']
match = get_target_match(target, targets)
print "Going nom on %s" % match