(Python) Statistical String Comparison

http://docs.python.org/library/difflib.html

  1. >>> import difflib
  2.  
  3. >>> difflib.SequenceMatcher(None, ‘abcde’, ‘abcde’).ratio()
  4. 1.0
  5.  
  6. >>> difflib.SequenceMatcher(None, ‘abcde’, ‘zbcde’).ratio()
  7. 0.80000000000000004
  8.  
  9. >>> difflib.SequenceMatcher(None, ‘abcde’, ‘zyzzy’).ratio()
  10. 0.0
This entry was posted in Python and tagged , , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Why ask?

  • Advertisement

  • Categories