列表如下:
results_list = [ { 'avgLasts': 3.2776, 'avgPv': 3.3061, 'brandVoucherAmount': 59500, 'browseUserNum': 1261, 'cargoValue': 79831980, 'cargoValueIncr': 19997900, 'cargoVolume': 6616, 'cargoVolumeIncr': 1536, 'customerComplaintNum': 0, 'customerComplaintRate': 0.0, 'customerPrice': 10274, 'dynamicBrowsingRate': 279.9166666666667, 'dynamicSaleRate': 0.4444444444444444, 'fullReductionAmount': 0, 'inventorySpu': 27, 'jointRate': 1.0, 'lasts': 3330, 'listUnitPrice': 10274, 'netSales': 405089, 'netSalesNum': 40, 'openOrderNum': 0, 'openOrderRate': 0.0, 'orderAmount': 476189, 'orderNum': 46, 'orderTransRate': 0.0443, 'orderUserNum': 45, 'payGoodsNum': 43, 'payOrderNum': 43, 'pv': 3359, 'receivedAmount': 336094, 'refundAmount': 36700, 'refundGoodsNum': 3, 'refundOrderNum': 3, 'refundRate': 0.0698, 'returnGoodsRate': 0.07894736842105263, 'salesAmount': 441789, 'salesNum': 43, 'salesSpu': 12, 'sendGoodsNum': 38, 'skipLossNum': 552, 'skipLossRate': 0.4377, 'technicalFee': 40670, 'turnTransRate': 0.0423, 'turnUserNum': 43, 'unitPrice': 10274, 'uv': 1016 }, { 'avgLasts': 3.3294, 'avgPv': 3.3782, 'brandVoucherAmount': 42707, 'browseUserNum': 1182, 'cargoValue': 101822780, 'cargoValueIncr': 0, 'cargoVolume': 8363, 'cargoVolumeIncr': 0, 'customerComplaintNum': 0, 'customerComplaintRate': 0.0, 'customerPrice': 11552, 'dynamicBrowsingRate': 187.58823529411765, 'dynamicSaleRate': 0.6071428571428571, 'fullReductionAmount': 0, 'inventorySpu': 28, 'jointRate': 1.025, 'lasts': 3143, 'listUnitPrice': 11552, 'netSales': 446180, 'netSalesNum': 40, 'openOrderNum': 0, 'openOrderRate': 0.0, 'orderAmount': 542280, 'orderNum': 45, 'orderTransRate': 0.0456, 'orderUserNum': 43, 'payGoodsNum': 41, 'payOrderNum': 40, 'pv': 3189, 'receivedAmount': 346984, 'refundAmount': 15900, 'refundGoodsNum': 1, 'refundOrderNum': 1, 'refundRate': 0.025, 'returnGoodsRate': 0.02564102564102564, 'salesAmount': 462080, 'salesNum': 41, 'salesSpu': 17, 'sendGoodsNum': 39, 'skipLossNum': 548, 'skipLossRate': 0.4636, 'technicalFee': 46094, 'turnTransRate': 0.0424, 'turnUserNum': 40, 'unitPrice': 11270, 'uv': 944 } ]
把results_list中两个字典元素的值相加求和。
如:
sales_amount = sum((int(item['salesAmount']) if 'salesAmount' in item else 0) for item in results_list) sales_sum = sum((int(item['salesNum']) if 'salesNum' in item else 0) for item in results_list)
表达式解释:先循环获取到列表中的字典元素,再根据字典的key获取值,获取到字典元素后,判断key是否在字典中,如果在就转化成int类型,否则直接赋值0;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)