python map
遍历序列,对序列中每个元素进行操作,最终获取新的序列。
传入一个函数和一个list
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # -*- coding: utf-8 -*- 2 3 li = [11, 22, 33] 4 5 new_list = map(lambda a: a + 100, li) 6 7 print new_list 8 9 ''' 10 运行结果: 11 [111, 122, 133] 12 [Finished in 0.1s] 13 14 '''
也可以传入一个函数和多个list
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 # -*- coding: utf-8 -*- 2 3 li = [11, 22, 33] 4 sl = [1, 2, 3] 5 new_list = map(lambda a, b: a + b, li, sl) 6 7 print new_list 8 9 ''' 10 result : 11 [12, 24, 36] 12 [Finished in 0.1s] 13 '''