将字典值添加到列表

时间:2017-11-30 20:04:35

标签: python list dictionary github

大家好我有一个函数收集指标,基本上调用两个函数get_open_prs()和calculate_warnings()

def collect_metrics():
                """function for collecting the desired metrics from github"""
                for owner,repo in config.REPOS_TO_CHECK:
                    pulls_url = get_open_prs(owner,repo)
                    desired_github_metrics = calculate_warnings(pulls_url, config.TOO_OLD_DAYS)
                    desired_github_metrics["owner"] = owner
                    desired_github_metrics["repo"] = repo
                    print desired_github_metrics #prints dictionary
if __name__ == "__main__":

    collect_metrics()

现在我打印collect_metrics()时得到的输出是:

{'owner': 'owner', 'repo': 'test_repo', 'days': 7}
{'owner': 'owner1', 'repo': 'test_repo1', 'days': 17}

我想要做的是返回desired_github_metrics而不是打印它,我希望该输出作为列表中的字典:

desired output:

    [{'owner': 'owner', 'repo': 'test_repo', 'days': 7}]
    [{'owner': 'owner1', 'repo': 'test_repo1', 'days': 17}]

这样当我调用collect_metrics函数时:

if __name__ == '__main__':
        data = collect_metrics()
        for my data in data:
            print(datum) 

#prints output
        [{'owner': 'owner', 'repo': 'test_repo', 'days': 7}]
        [{'owner': 'owner1', 'repo': 'test_repo1', 'days': 17}]

0 个答案:

没有答案