problem2.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:STA141C 作者: clarkfitzg 项目源码 文件源码
def overlap_score(q1, q2):
    """
    q1, q2 are preprocessed sentences (strings)

    >>> overlap_score("a b", "a")
    0.6666666666666666

    """

    c1 = Counter(q1.split())
    c2 = Counter(q2.split())
    c1c2 = c1 + c2

    both = set(c1.keys())
    both = both.intersection(c2.keys())

    bothscore = float(sum(c1c2[x] for x in both))
    mplusn = float(sum(c1c2.values()))

    score = bothscore / mplusn

    return score
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号