首页 > 其他分享 >老是忘记的字典排序

老是忘记的字典排序

时间:2023-03-28 17:45:44浏览次数:33  
标签:product group consume lst 老是 amount dict 排序 字典

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)
 

标签:product,group,consume,lst,老是,amount,dict,排序,字典
From: https://www.cnblogs.com/uglyliu/p/17266101.html

相关文章

  • 重要的事情老是忘记怎么办?怎么设置日期提醒的闹钟?
    对于很多人来说,生活和工作一直都是各种琐事和重要事项交织出现的,一些不太重要的琐事,我们忘记的话,后续想起来再去完成就可以了。但是如果忘记的是比较重要的事情,例如重要会......
  • python笔记3(字典)
    字典1.字典的创建1.{}2.dict()3.通过fromkeys创建值为空的字典2.字典元素的访问通过get()方法以a={"name":"jiachao","age":20,"school":"tongda"}为例如若结......
  • 选择排序
    欢迎关注fish的公众号:fish码农成长之旅相信大家对扑克牌并不陌生,当我们在齐牌的时候是不是会按照大小顺序进行排列,选择排序的过程就跟扑克牌差不多一样的直观简单。其......
  • Java学习----冒泡排序
    冒泡排序importjava.util.Arrays;publicclassMaoPaoPaiXu{publicstaticvoidmain(String[]args){int[]a={1,2,3,5,7,9,22,44,63,75};......
  • 吃巧克力,容器vector、map,容器适配器 priority_queue,算法sort排序
     #include<algorithm>#include<queue>#include<map>#include<vector>#include<iostream>usingnamespacestd;structchocolate{longlonga;//价......
  • 八大排序
    冒泡排序publicstaticvoidbubbleSort(int[]array){intlength=array.length;for(inti=0;i<length;i++){for(int......
  • Winform/Csharp中使用Linq的Where条件筛选、Select字段映射(左外连接并设置无匹配时默
    场景Java8新特性-Stream对集合进行操作的常用API:https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/126070657上面讲的是在Java中使用Stream中对集合的常用操......
  • C语言—模范qsort()实现一个冒泡排序的通用算法
    目录一、库方法qsort参数解释二、冒泡排序解释三、模拟实现1、冒泡排序函数2、数值交换函数3、测试函数4、运行结果5、源代码一、库方法qsort参数解释二、冒泡排序解释三、......
  • 简述几种常用的排序算法
    摘要:归并排序和快速排序是两种稍微复杂的排序算法,它们用的都是分治的思想,代码都通过递归来实现,过程非常相似。理解归并排序的重点是理解递推公式和merge()合并函数。本......
  • 五种Python中字典的高级用法
    用作switch/case在许多编程语言中,switch/case语句允许大家根据变量的值来执行不同的操作。虽然Python没有内置的switch/case语句,但是大家可以通过使用字典来实现类似的功......