#-----在字典中循环 dict1={'name':'caiquan','sex':'nan','age':'24','state':'1'} for k,b in enumerate(dict1.iteritems()): print k,b #-----在序列中循环 seq1=['tea','apple','peak','banan'] for m in enumerate(seq1): print m #-----在多个序列中循环 question=['name','sex','age','state'] answer=['caiquan','nan','24','0'] anth=['22','33','44','55'] for q,n,a in zip(question,answer,anth): print 'question is %s , answer is %s, age is %s'% (q,n,a) #--(1,10)之间倒序排序,间隔为2 for i in reversed(xrange(1,10,2)): print i #--无重复元组 xulie=['aa','bb','cc','dd','ee','aa','bb'] for f in sorted(set(xulie)): print f
输出结果:
0 ('age', '24') 1 ('state', '1') 2 ('name', 'caiquan') 3 ('sex', 'nan') (0, 'tea') (1, 'apple') (2, 'peak') (3, 'banan') question is name , answer is caiquan, age is 22 question is sex , answer is nan, age is 33 question is age , answer is 24, age is 44 question is state , answer is 0, age is 55 9 7 5 3 1 aa bb cc dd ee