#Returns a set of matches from the given list. Its a tuple, containing
#the match location of both the Sequence followed by the size
matches = SequenceMatcher(None, a , b).get_matching_blocks()[:-1]
#Now its straight forward, just extract the info and represent in the manner
#that suits you
[a[e.a: e.a + e.size] for e in matches]
[[1, 2], [5, 6]]
您可以为此使用difflib.SequenceMatcher
使用集:
您可以使用支持python交集的sets
s.intersection(t) s & t new set with elements common to s and t
相关问题 更多 >
编程相关推荐