当前位置: 首页 > news >正文

Python convert list to dict.

import uuid
from datetime import datetime
import time
import pandas as pd
import pymysql
import asyncioclass Book:def __init__(self,id,name,isbn,author,comment,content,summary,title,topic):self.id=idself.name=nameself.isbn=isbnself.author=authorself.comment=commentself.content=contentself.summary=summaryself.title=titleself.topic=topicdef to_dict(self):return {'Id':self.id,'Name':self.name,'ISBN':self.isbn,'Author':self.author,'Comment':self.comment,'Content':self.content,'Summary':self.summary,'Title':self.title,'Topic':self.topic}data_list=[]
arr=range(1,10001)
for a in arr:data_list.append(Book(a,f'Name_{a}',f'ISBN_{a}_{uuid.uuid4().hex}',f'Author_{a}',f'Comment_{a}',f'Content_{a}',f'Summary_{a}',f'Title_{a}',f'Topic_{a}'))dic={bk.id:bk for bk in data_list}for k,v in dic.items():print(f'Key:{k},value:{v.to_dict()}')

 

 

Key:9992,value:{'Id': 9992, 'Name': 'Name_9992', 'ISBN': 'ISBN_9992_7da6fdf7f7e0404680bf4b994df0cdb6', 'Author': 'Author_9992', 'Comment': 'Comment_9992', 'Content': 'Content_9992', 'Summary': 'Summary_9992', 'Title': 'Title_9992', 'Topic': 'Topic_9992'}
Key:9993,value:{'Id': 9993, 'Name': 'Name_9993', 'ISBN': 'ISBN_9993_4a45866877734ad8918a90db70189a3f', 'Author': 'Author_9993', 'Comment': 'Comment_9993', 'Content': 'Content_9993', 'Summary': 'Summary_9993', 'Title': 'Title_9993', 'Topic': 'Topic_9993'}
Key:9994,value:{'Id': 9994, 'Name': 'Name_9994', 'ISBN': 'ISBN_9994_25cfc9ecec9545ef9ccb3bc6b7db2c77', 'Author': 'Author_9994', 'Comment': 'Comment_9994', 'Content': 'Content_9994', 'Summary': 'Summary_9994', 'Title': 'Title_9994', 'Topic': 'Topic_9994'}
Key:9995,value:{'Id': 9995, 'Name': 'Name_9995', 'ISBN': 'ISBN_9995_70cb5cdbf1ef4638a36e2faaa339f121', 'Author': 'Author_9995', 'Comment': 'Comment_9995', 'Content': 'Content_9995', 'Summary': 'Summary_9995', 'Title': 'Title_9995', 'Topic': 'Topic_9995'}
Key:9996,value:{'Id': 9996, 'Name': 'Name_9996', 'ISBN': 'ISBN_9996_6e3d47c0fd09475d97ab70b3bf01e1dc', 'Author': 'Author_9996', 'Comment': 'Comment_9996', 'Content': 'Content_9996', 'Summary': 'Summary_9996', 'Title': 'Title_9996', 'Topic': 'Topic_9996'}
Key:9997,value:{'Id': 9997, 'Name': 'Name_9997', 'ISBN': 'ISBN_9997_fa3fdc5bacee49d1b4335ee4971985c0', 'Author': 'Author_9997', 'Comment': 'Comment_9997', 'Content': 'Content_9997', 'Summary': 'Summary_9997', 'Title': 'Title_9997', 'Topic': 'Topic_9997'}
Key:9998,value:{'Id': 9998, 'Name': 'Name_9998', 'ISBN': 'ISBN_9998_7f6eb6bd01f14983966ad3b8aea889ec', 'Author': 'Author_9998', 'Comment': 'Comment_9998', 'Content': 'Content_9998', 'Summary': 'Summary_9998', 'Title': 'Title_9998', 'Topic': 'Topic_9998'}
Key:9999,value:{'Id': 9999, 'Name': 'Name_9999', 'ISBN': 'ISBN_9999_9eb43b2c40334094a8bf1c77195926eb', 'Author': 'Author_9999', 'Comment': 'Comment_9999', 'Content': 'Content_9999', 'Summary': 'Summary_9999', 'Title': 'Title_9999', 'Topic': 'Topic_9999'}
Key:10000,value:{'Id': 10000, 'Name': 'Name_10000', 'ISBN': 'ISBN_10000_ff3efce3cd7c48aeb7b1b2c288d5d06a', 'Author': 'Author_10000', 'Comment': 'Comment_10000', 'Content': 'Content_10000', 'Summary': 'Summary_10000', 'Title': 'Title_10000', 'Topic': 'Topic_10000'}

 

 

image

 

http://www.jsqmd.com/news/357146/

相关文章:

  • 告别卡顿与限流:一份面向开发者的VK视频高效下载与本地化方案
  • 深入解析VK视频下载技术:从HLS流媒体到高效下载方案实现
  • springboot某单位消防安全在线管理平台-开题报告
  • 一个简单神奇的正弦震荡电路
  • springboot欢乐亲子旅游网站-开题报告
  • leetcode 921. Minimum Add to Make Parentheses Valid 使括号有效的最少添加-耗时100
  • springboot开题报告房屋租赁管理系统
  • 当使用自定义Host头时,cURL中的跨源Cookie泄漏与注入风险
  • springboot开题报告英语学习助手
  • 强连通分量+缩点
  • Linux命令-lprm(删除打印队列中任务)
  • 企业级音频内容管理:从混沌到有序的语音检索系统构建指南
  • 基于浏览器开发者工具的VK视频下载方案实践
  • 突破实时音频分析瓶颈:边缘AI技术让语音理解提速8倍
  • Linux命令-lpstat(查看打印机状态和打印队列信息)
  • 深入解析:STM32初学---总线:AHB、AHP / EEPROM、SPI FLASH、EMMC
  • Mac软件汉化完全指南:Axure RP 11界面本地化实操
  • 基于SimCLR的自监督 YOLO:YOLOv5/8也能在低标注场景目标检测性能飙升 - 实践
  • 【WC 2026】 游记
  • 3步突破软件本地化障碍:从效率损耗到用户体验升级
  • Midscene.js调试工具终极指南:Playground与Chrome扩展完全手册
  • Java序列化从入门到精通:核心原理、实战应用与进阶优化
  • 智能驱动下的隐写术探查新范式:自动化工具体系与技术演进
  • 5大突破!抖音视频批量采集工具让内容获取效率提升300%的实战指南
  • YimMenu革新性全景指南:重新定义GTA5游戏增强工具体验
  • n8n自动化平台爆6个高危漏洞,4个RCE可致服务器完全接管,全网紧急升级预警
  • 5个技巧让游戏自动化效率工具为你解放双手
  • 视频资源获取工具高效解决方案:从入门到精通的全方位指南
  • 基于PHP、asp.net、java、Springboot、SSM、vue3的会议室管理系统的设计与实现
  • 【含文档+PPT+源码】基于微信小程序的房屋租赁系统