#encoding=utf-8 #enumerate 是python中的内置函式 #enumerate(iterable) #适合for循环,可以同时循环序号和元素 mylist=["a","b","c","d","e","f"] print enumerate(mylist) for index,object in enumerate(mylist): print index,object #结果为 #1 a #1 b #2 c #3 d #4 e #5 f #map() #函式说明map(function,sequence[,sequence,.....])->list #第一个参数是函数,第二个是列表或元组 print map(lambda x:x*2,[1,2,3,4,5,6,7]) #结果[2, 4, 6, 8, 10, 12, 14] #zip #函式说明 zip(seq1,seq2[.....]) ->[(seq1[0],seq2[0]...),(...)] print zip([1,2,3,4,5],[11,12,13,14,15],[21,22,23,24,25]) #返回一个列表[(1, 11, 21), (2, 12, 22), (3, 13, 23), (4, 14, 24), (5, 15, 25)] for x,y in zip([1,2,3],[4,5,6]): print "x,y:",x,y #filter #说明: filter(function or None,sequence) ->list,tuple,or string #参数一:函数 参数二:列表 #根据function参数返回的结果是否为真,来对list进行过滤 print filter(lambda x:x>3,[1,2,3,4,5,6,7]) #结果:[4, 5, 6, 7]