dict去重python_python dict 以key名 去重运算

将日期相同的数据统计在一起

a_count = [

{'create_time': '2020-03-05', 'total_len': 1, 'count_invite': 1},

{'create_time': '2020-03-11', 'total_len': 2, 'count_invite': 2},

{'create_time': '2020-03-18', 'total_len': 2, 'count_invite': 2},

{'create_time': '2020-03-06', 'total_len': 1, 'count_invite': 1},

{'create_time': '2020-03-04', 'total_len': 1, 'count_invite': 1},

{'create_time': '2020-03-15', 'total_len': 2, 'count_invite': 2},

{'create_time': '2020-03-19', 'total_len': 1, 'count_invite': 1},

{'create_time': '2020-03-27', 'total_len': 3, 'count_invite': 3},

{'create_time': '2020-03-25', 'total_len': 64, 'count_invite': 59},

{'create_time': '2020-03-25', 'total_len': 3, 'count_invite': 2},

{'create_time': '2020-03-25', 'total_len': 1, 'count_invite': 1}

]

for i ina_count:for data ini:

date_list.append(data)

new_list=[]for i indate_list:if i["create_time"] not innew_list:

new_list.append(i["create_time"])

new_data_list=[]for date_obj innew_list:

new_dic= {'create_time': date_obj, 'total_len': 0, 'count_invite': 0, 'count_invite': 0}for old indate_list:if old["create_time"] ==date_obj:

new_dic["total_len"] += old["total_invite_len"]

new_dic["count_invite"] += old["count_email_invite"]

new_dic['count_invite'] = new_dic["total_len"] - new_dic["count_invite"]

new_data_list.append(new_dic)

你可能感兴趣的:(dict去重python)