recipe-577982.py 文件源码

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

项目:code 作者: ActiveState 项目源码 文件源码
def objwalk(obj, path=(), memo=None):
    if memo is None:
        memo = set()
    iterator = None
    if isinstance(obj, Mapping):
        iterator = iteritems
    elif isinstance(obj, (Sequence, Set)) and not isinstance(obj, string_types):
        iterator = enumerate
    if iterator:
        if id(obj) not in memo:
            memo.add(id(obj))
            for path_component, value in iterator(obj):
                for result in objwalk(value, path + (path_component,), memo):
                    yield result
            memo.remove(id(obj))
    else:
        yield path, obj

# optional test code from here on
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号