小编Pan*_*cks的帖子

如何使用嵌套for循环来改进此功能?

我想知道如何使用嵌套for循环来提高此函数的可读性.也许我可以用nested for looptags_files =

def search_repotag_for_file(search_filepath, repo):
    '''Goes through all tags, all files to find a github file entity
       which matches the search_filepath we are looking for'''
    all_tags = (tag for tag in repo.tags)
    tags_files = ((tag, file_ent) for tag in all_tags for file_ent in tag.commit.tree.traverse())
    matches = (tup for tup in tags_files if tup[1].path == search_filepath)
    return matches
Run Code Online (Sandbox Code Playgroud)

python for-loop nested generator

0
推荐指数
1
解决办法
40
查看次数

标签 统计

for-loop ×1

generator ×1

nested ×1

python ×1