欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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
相关标签: python map