fork download
  1. from difflib import get_close_matches
  2.  
  3. def get_target_match(target, targets):
  4. '''
  5. Approximates a match for a target from a sequence of targets,
  6. if a match exists.
  7. '''
  8.  
  9. matches = get_close_matches(target, targets)
  10. print target, targets
  11. print matches
  12. return matches and matches[0] or None
  13.  
  14. target = 'z'
  15. targets = ['Joe', 'Bob', 'zombie', 'Susan', 'kobold', 'Bill']
  16. match = get_target_match(target, targets)
  17. print "Going nom on %s" % match
Success #stdin #stdout 0.12s 11640KB
stdin
Standard input is empty
stdout
z ['Joe', 'Bob', 'zombie', 'Susan', 'kobold', 'Bill']
[]
Going nom on None