#coding=utf-8
a=[1,2,3,4,5,6,7,8,9,10,11,12,13,14]
#每行显示6个列表元素
for i,v in enumerate(a):
if i!=0 and i%6==0:
print
print v,
' '*2+'Type:',type(v),'\n'#取得列表数据的类型,换行
结果:
********************List enumerate()********************
The 0 element in list is:1 Type:
The 1 element in list is:abc Type:
The 2 element in list is:3 Type:
The 3 element in list is:I am a boy Type:
The 4 element in list is:2.34 Type:
The 5 element in list is:-9 Type:
********************String enumerate()********************
The 0 element in list is:1 Type:
The 1 element in list is:a Type:
The 2 element in list is:b Type:
The 3 element in list is:3 Type:
The 4 element in list is:4 Type:
The 5 element in list is:c Type:
The 6 element in list is:d Type:
********************Tuple enumerate()********************
The 0 element in list is:1 Type:
The 1 element in list is:abc Type:
The 2 element in list is:2.3 Type:
The 3 element in list is:5.6 Type:
The 4 element in list is:I am a boy Type:
l=range(10)
#方法一
for i in l:
print i,
if i!=0 and i%5==0:
print
print
#方法二
for m in l:
if m!=0 and m%6==0:
print
print m,
有一个list = ["a","b","c","d"],想要转化成一个dict = ["1":"a","2":"b","3":"c","4":"d"]
dict([str(i+1),j for i,j in enumerate(list)])