compare.py 文件源码

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

项目:deoplete-latex 作者: poppyschmo 项目源码 文件源码
def fake_deepdiff(one, two, indent=4, path=None, strict_strings=None):
    """Compare two term dictionaries. ``strict_strings=False`` treats
    strings that contain the same combination of words as equal.
    """
    for k, v in one.items():
        _one = v
        _two = two.get(k)
        if _one == _two:
            continue
        if all(isinstance(d, abc.MutableMapping) for d in (_one, _two)):
            _path = path if path is not None else []
            _path += ['{:<{width}}{}'.format('', k, width=indent)]
            fake_deepdiff(_one, _two, indent + 4, _path, strict_strings)
            continue
        if (all(isinstance(l, abc.MutableSequence) for l in (_one, _two)) and
                set(tuple(x) for x in _one if isinstance(x, abc.Sequence)) ==
                set(tuple(x) for x in _two if isinstance(x, abc.Sequence))):
            continue
        if all(isinstance(l, str) for l in (_one, _two)):
            if (strict_strings is False and
                    set(c.strip(';:,.?=_-\n') for c in _one.split()) ==
                    set(c.strip(';:,.?=_-\n') for c in _two.split())):
                continue
            else:
                _one = _one.strip().replace('\n', '')
                _two = _two.strip().replace('\n', '')
        print('\n'.join(path) if path else '')
        print('{:<{width}}{}'.format('', k, width=indent))
        print('{:<{width}}one: {}'.format('', _one, width=indent + 4))
        print('{:<{width}}two: {}'.format('', _two, width=indent + 4))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号