python - 字典之间的格式转换参考
2023-09-27 14:29:10 时间
# coding=utf-8
result = [
{"type": "MYSQL", "host": "going", "count": "100"},
{"type": "MYSQL", "host": "success", "count": "200"},
{"type": "MYSQL", "host": "failed", "count": "300"},
{"type": "redis", "host": "going", "count": "400"},
{"type": "redis", "host": "success", "count": "500"},
{"type": "redis", "host": "failed", "count": "600"},
]
def make_data(result):
ret = []
type_list = []
for t in result:
type = t.get("type")
if type not in type_list:
type_list.append(type)
print '\n'
print "type_list = ", type_list
for i in type_list:
a = dict()
for t in result:
if t.get("type") == i:
a.update({t.get('host'): t.get('count')})
a.update({"type": i})
print 'a = ', a
ret.append(a)
return ret
if __name__ == "__main__":
# print "ret = ", ret
ret = make_data(result)
print 'ret_finally = ', ret
相关文章
- python中,如何将字符串转换为数字(将数字转换为整型),字符串的10转换为整型的10,10.5转换为10
- python中,如有个非常长的字符串,在写的时候如何将其分隔
- python把其他图片格式转换成jpg
- python 的 reshape强制转换格式的用途
- Python 复制文件、移动文件、拷贝文件(shutil)
- Python global文件的全局变量使用
- Python 获取(字典)字符串时间区间并转换类型,判断该时间段属否在时间范围
- Python 16进制与字符串的转换、二进制 to 十进制、十六进制 to 十进制、十进制 to 二进制
- Word处理控件Aspose.Words功能演示:使用 Python 将 Word 文档转换为 TIFF
- Word处理控件Aspose.Words功能演示:在 Python 中将 PDF 文件转换为 HTML
- 使用python将中文与Unicode编码相互转换
- python转换数据类型(int、float、str、eval、tuple、list、chr、ord、bin、oct、hex)
- Python自动化测试面试题-编程篇
- python面对对象-使用@property
- Python 格林威治时间格式 Wed Jul 10 20:00:09 +0800 2019 转换为标准时间格式年月日时分秒%Y-%m-%d %H:%M:%S
- 在ubuntu下随意编译安装需要的python版本
- 【Python】+数字时间戳转换为指定格式
- 【Python】+字符串转换为日期(互转)+获取当前时间+获取当前时间戳
- 《Python Cookbook(第2版)中文版》——1.21 在Unicode和普通字符串之间转换
- 《树莓派Python编程入门与实战》——3.6 关于Python开发环境shell
- python 编码和解码
- (数据科学学习手札65)利用Python实现Shp格式向GeoJSON的转换
- Python将十进制数值和二进制数值进行相互转换
- pip install --user 使用方法和注意事项——python中安装module库到用户packages路径中
- python绘图库matplotlib:画线的标志marker的设置——类型/size/空心/边线颜色及大小/显示marker超出边界部分
- python之input()、while、title()和upper()
- Python 获取Google+特定用户最新动态
- python 中json和字符串互相转换