Skip to content

map

请查看 Python 内建函数列表 了解更多相关 API。

说明:将可迭代对象进行映射。

python
def map(fn, iterable):
    '''
    将可迭代对象进行映射

    :param fn: 回调函数,返回元素映射后的值
    :param iterable: 要过滤的可迭代对象
    :return: 映射后的可迭代对象
    '''

示例:

python
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]
print(map(lambda x : x**2, numbers))
print(list(map(lambda x : x**2, numbers)))