difflib [对象比较]

    import difflib
    s1 = ['bacon\n', 'eggs\n', 'ham\n', 'guido\n']
    s2 = ['python\n', 'eggy\n', 'hamster\n', 'guido\n']
    for line in difflib.context_diff(s1, s2, fromfile='txt-s1', tofile='txt-s2'):    
    # 两字列表比较差异
        sys.stdout.write(line)

    difflib.get_close_matches('appel', ['ape', 'apple', 'peach', 'puppy'])           
    # 模糊匹配 匹配列表与字符串相似的值,越相似越靠前
文档更新时间: 2018-11-21 17:37   作者:RuM