码迷,mamicode.com
首页 > 编程语言 > 详细

列表字符串字典互转,enumerate

时间:2018-09-11 18:00:44      阅读:266      评论:0      收藏:0      [点我收藏+]

标签:min   标识   列表   元祖   type   list   数据   kong   items   

列表转换成字符串

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

列表字符串字典互转,enumerate

标签:min   标识   列表   元祖   type   list   数据   kong   items   

原文地址:http://blog.51cto.com/12992048/2173897

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!