使用counter求两个子串相似度问题

from collections import Counter
def longSim():
    L1 = "abcdefg1223"
    L2 = "abcd88ut1g2f23"
    m = len(L1)
    n = len(L2)

    if m == 0 and n == 0:
        return 1.0
    elif (m * n == 0):
        if m < 10 or n < 10:
            return 0.3
        else:
            return 0.0
    else:

    c1 = Counter(L1)
    print c1

    c2 = Counter(L2)
    print c2

    d1 = dict(c1)
    print d1

    d2 = dict(c2)
    print d2

    count = 0
    print set(c1)&set(c2)
    for i in set(c1)&set(c2):

        print "-----------%d"%d1[i]

        count += min(d1[i],d2[i])
        print float(count)/max(m,n)


longSim()

你可能感兴趣的:(python学习)