python合并list中各個字典中相同條件的累計數

來源:互聯網
上載者:User

標籤:new   refresh   end   json   test   []   python   條件   summary   

#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()

python合并list中各個字典中相同條件的累計數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.