main.py 文件源码

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

项目:flashcard 作者: sotetsuk 项目源码 文件源码
def get_diff_with_color(expected: str, ans: str) -> Tuple[str, str]:
    d = difflib.Differ()
    diff = d.compare(expected, ans)

    expected_with_mistake = ""
    ans_with_mistake = ""
    for e in diff:
        if e.startswith("+"):
            ans_with_mistake += colored(e[-1], "red")
        elif e.startswith("-"):
            expected_with_mistake += colored(e[-1], "green")
        else:
            expected_with_mistake += e[-1]
            ans_with_mistake += e[-1]

    return expected_with_mistake, ans_with_mistake
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号