map函数使用例子
程序员文章站
2022-04-02 22:04:34
...
example1:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: json_steve
def test1(data):
print data
data_list = [1, 2, 3, 4, 5]
map(test1, data_list)
结果:
1
2
3
4
5
example2:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: json_steve
from multiprocessing.dummy import Pool # 线程池
def test1(data):
print data
data_list = [1, 2, 3, 4, 5]
pools = Pool(len(data_list))
pools.map(test1, data_list)
pools.close()
pools.join()
结果
1
2
3
4
5