How to find the overlap between 2 sequences, and return it

前端 未结 4 2081
逝去的感伤
逝去的感伤 2020-12-02 23:45

I am new in Python, and have already spend to many hours with this problem, hope somebody can help me. I need to find the overlap between 2 sequences. The overlap is in the

4条回答
  •  甜味超标
    2020-12-03 00:33

    You could use difflib.SequenceMatcher:

    d = difflib.SequenceMatcher(None,s1,s2)
    >>> match = max(d.get_matching_blocks(),key=lambda x:x[2])
    >>> match
    Match(a=8, b=0, size=39)
    >>> i,j,k = match
    >>> d.a[i:i+k]
    'GGCTCCCCACGGGGTACCCATAACTTGACAGTAGATCTC'
    >>> d.a[i:i+k] == d.b[j:j+k]
    True
    >>> d.a == s1
    True
    >>> d.b == s2
    True
    

提交回复
热议问题