python dict怎么转成list?
2个回答
展开全部
通常dict转list:
dic = dict(a=1, b=2, c='something')
result = list(dic.items())
dict没办法转换成一个list
倒是dict的键和值可以分别转换为一个listmylist=[]
forainrange(0,10000):
mylist.append((a,a+1,a+2,a+3,a+4))
myDict={}
forkeyinmylist:
myDict[key[0]]=key[1:]
printmyDict
usr/bin/envpython
coding:utf-8-
list_=[(1,0.2,90,24,21),(2,0.2,90,24,21),(3,0.2,90,24,21)]
dict_={i[0]:i[1:]foriinlist_}
#dict_={str(i[0]):i[1:]foriinlist_}
printdict_
RESTART:C:/Users/Administrator/Deskto{1:(0.2,90,24,21),2:(0.2,90,24,21),3:(0.2,90,24,21)}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询