元组转换为字典

import pymysql
from collections import defaultdict

conn = pymysql.connect(host='*', user='*', password="*", database='*')

cur = conn.cursor()
cur.execute('select * from t5')
ret = cur.fetchall()
print(ret)

dic = defaultdict(list)
for i in range(len(ret)):
dic[ret[i][0]].append(ret[i][1])
for key in dic:
print(dic[key])
posted @ 2020-04-06 09:28  笑而不语心自闲  阅读(279)  评论(0编辑  收藏  举报