```# 列表转换成字符串
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))
# 字典转换成列表,数据成为元祖(都能够循环输出)
## 方法1
infoo={'on1':"张家辉",
'on2':"xuwuming",
'on3':"sunwukong"}
print(infoo.items())#把自己转换成列表
#dict_items([('on1', '张家辉'), ('on2', 'xuwuming'), ('on3', 'sunwukong')])
for k,v in infoo.items:
print("\t",k,v)
## 方法2
a=list(infoo.items())
print(a)
print(a[0][1])
#[('on1', '张家辉'), ('on2', 'xuwuming'), ('on3', 'sunwukong')
for k,v in infoo.items:
print("\t",k,v)
# 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
转载来源:
http://kswsj.cn/article/iehcco.html