老是忘记的字典排序

发布时间 2023-03-28 17:39:30作者: 梦轻尘
amount_total = 0
for subscription_type, product_info in bill_group_dict.items():
consume_group_doc_lst["subscription_type"] = subscription_type
consume_group_doc_lst["billing_date_begin"] = billing_date_begin
consume_group_doc_lst["billing_date_end"] = billing_date_end
for product_name, amount in product_info.items():
amount_total += amount
consume_group_doc_lst["product_name"] = product_name
consume_group_doc_lst["amount"] = amount
price_dict[product_name] = amount
sorted_dict = {k: v for k, v in sorted(price_dict.items(), key=lambda item: item[1], reverse=True)}

for key, value in sorted_dict.items():
count_list.append(value)
str_content += f'{key}: {float(value)}¥\n'
consum_total = '总消费:' + str(round(sum(count_list), 2)) + '¥'
content = str_content + consum_total
print(content)