### python里使用difflib庫的比較文本時丟棄不要的字符

`#python 3.6#蔡軍生 #http://blog.csdn.net/caimouse/article/details/51749579#from difflib import SequenceMatcherdef show_results(match):    print('  a    = {}'.format(match.a))    print('  b    = {}'.format(match.b))    print('  size = {}'.format(match.size))    i, j, k = match    print('  A[a:a+size] = {!r}'.format(A[i:i + k]))    print('  B[b:b+size] = {!r}'.format(B[j:j + k]))A = " abcd"B = "abcd abcd"print('A = {!r}'.format(A))print('B = {!r}'.format(B))print('\nWithout junk detection:')s1 = SequenceMatcher(None, A, B)match1 = s1.find_longest_match(0, len(A), 0, len(B))show_results(match1)print('\nTreat spaces as junk:')s2 = SequenceMatcher(lambda x: x == " ", A, B)match2 = s2.find_longest_match(0, len(A), 0, len(B))show_results(match2)`

A = ' abcd'
B = 'abcd abcd'

Without junk detection:
a    = 0
b    = 4
size = 5
A[a:a+size] = ' abcd'
B[b:b+size] = ' abcd'

Treat spaces as junk:
a    = 1
b    = 0
size = 4
A[a:a+size] = 'abcd'

B[b:b+size] = 'abcd'