map()函数

  参数:map(func,var)  注:var为可迭代的对象,例如列表,元组等

  作用:对取可迭代对象中的每一个元素对函数进行映射,得到一个map对象(python3.x)

     常见用法:

list1 = [1,2,3,4,5]
def add(args):
    return args+100

list2 = list(map(add,list1))
print(list2)#[101, 102, 103, 104, 105]

def f(x):
    return x*x
print(set(map(f, (1, 2, 3, 4, 5, 9,3)))) #{1, 4, 9, 16, 81, 25}
原文地址:https://www.cnblogs.com/sxh-myblogs/p/8298356.html