Advertisement
rfmonk

difflib_junk.py

Jan 8th, 2014
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. from difflib import SequenceMatcher
  5.  
  6.  
  7. def show_results(s):
  8.     i, j, k = s.find_longest_match(0, 5, 0, 9)
  9.     print ' i = %d' % i
  10.     print ' j = %d' % j
  11.     print ' k = %d' % k
  12.     print ' A[i:i+k] = %r' % A[i:i + k]
  13.     print ' B[j:j+k] = %r' % B[j:j + k]
  14.  
  15. A = " abcd"
  16. B = "abcd abcd"
  17.  
  18. print 'A = %r' % A
  19. print 'B = %r' % B
  20.  
  21. print '\nWithout junk detection:'
  22. show_results(SequenceMatcher(lambda x: x == " ", A, B))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement