• python合并list中各个字典中相同条件的累计数


    #coding: utf-8

    import json

    def test():

    aa = [{u'iTestID': 92478, u'all_case_count': 45103, u'refresh_time': u'2016-11-29 17:03:01', u'version_num': u'BaseOn_W16.38_PassList_0916', u'test_month': u'09', u'bug_count': 347, u'fail_count': 420,u'test_week': u'37', u'summary_type': u'TRUNK', u'confirm_rate': u'100.0000%', u'pass_count': 44683, u'test_year': u'2016', u'id': 716}, {u'iTestID': 92477, u'all_case_count': 953, u'refresh_time': u'2016-11-29 17:03:01', u'version_num': u'FM_BASE_W16.38', u'test_month': u'09', u'bug_count': 188, u'fail_count': 301, u'test_week': u'37', u'summary_type': u'TRUNK', u'confirm_rate': u'100.0000%', u'pass_count': 652, u'test_year': u'2016', u'id': 717}]

    result = []
    for i in range(0,len(aa)):
    sum_all_case_count,sum_pass_count,sum_bug_count, sum_fail_count,flag,sum_oldfail_count,sum_newfail_count = 0,0,0,0,0,0,0
    for r in result:
    bb = aa[i]['version_num'].split('_W')
    if bb[1][:5] in r['version_num']:
    flag = 1
    if flag == 0:
    for j in range(0,len(aa)):
    print aa[j]['version_num'].split('_W')
    if (aa[i]['version_num'].split('_W'))[1][:5] in (aa[j]['version_num'].split('_W')[1]):
    #aa[i]['version_num'] = (aa[i]['version_num'].split('_W'))[1][0:5]
    sum_all_case_count = sum_all_case_count+aa[j]['all_case_count']
    sum_pass_count = sum_pass_count+aa[j]['pass_count']
    sum_bug_count = sum_bug_count+aa[j]['bug_count']
    sum_fail_count = sum_fail_count+aa[j]['fail_count']
    if 'FM_BASE' in aa[j]['version_num']:
    sum_oldfail_count = sum_oldfail_count +aa[j]['fail_count']
    if 'PassList' in aa[j]['version_num']:
    sum_newfail_count = sum_newfail_count +aa[j]['fail_count']
    one_record = dict(version_num=aa[i]['version_num'],
    sum_all_case_count=sum_all_case_count,
    sum_pass_count=sum_pass_count,
    sum_bug_count=sum_bug_count,
    sum_fail_count=sum_fail_count,
    sum_oldfail_count=sum_oldfail_count,
    sum_newfail_count =sum_newfail_count
    )

    result.append(one_record)
    print result

    if __name__ == '__main__':
    test()

  • 相关阅读:
    测试
    201920201 20199320《Linux内核原理与分析》第四周作业
    201920201 20199320《Linux内核原理与分析》第六周作业
    201920201 20199320《Linux内核原理与分析》第五周作业
    201920201 20199320《Linux内核原理与分析》第七周作业
    201920201 20199320《Linux内核原理与分析》第一周作业
    201920201 20199320《Linux内核原理与分析》第八周作业
    ASP.NET MVC3 Custom FormAuthorize
    堆排序练习题
    面试题:4亿里有多少个1(11算2个)。
  • 原文地址:https://www.cnblogs.com/lzpblog/p/6125411.html
Copyright © 2020-2023  润新知