python 3 map函数用法

公式

f是定义的函数,l是你的list,所有功能都在f函数里完成,

map(f,l)

有些网址爬虫出来的链接是一部分,省略了前端通用的,这时我们需要补充进去,

这时就用到了map函数,批量补充网址,

举个栗子:

a=['aa','bb','cc','dd']    #随意一个列表

def f(x):   #定义函数
    y = 'https://hellowoed.ddf.fff/'+x
    return y

b=(map(f,a))       #用MAP函数把省略的部分统一加在每一个网址里
print(list(b))     #python 3之后必须使用list才可以看到list结果,
#不然结果是<map object at 0x000001E3879E1518>

  

结果是

['https://hellowoed.ddf.fff/aa',
 'https://hellowoed.ddf.fff/bb',
 'https://hellowoed.ddf.fff/cc',
 'https://hellowoed.ddf.fff/dd']