列表字符串字典互转,enumerate

列表转换成字符串

max=[1,2,3,4,5,6,7,8,9,10]
max_str=str(max)
max_list=list(str(max))
print(str(max))
print (max_list)
print (type(max_str))
print (type(max_list))

#字典转换成列表,数据成为元祖
infoo={'on1':"张家辉",
'on2':"xuwuming",
'on3':"sunwukong"}
print(infoo.items())#把自己转换成列表
#[('on1', '张家辉'), ('on2', 'xuwuming'), ('on3', 'sunwukong')]

enumerate

kl=['alex','jack','tadd','moth']
kl[1]='end'
for i,j in enumerate(kl): #同时输出 标识与元素
print(i,j)
#0 alex
#1 end
#2 tadd
#3 moth

猜你喜欢

转载自blog.51cto.com/12992048/2173897