python中的map和reduce学习

参考自:https://github.com/qiwsir/StarterLearningPython/blob/master/204.md#map

    https://github.com/qiwsir/StarterLearningPython/blob/master/204.md#reduce

map(函数名/函数表达式(lambda等)/....  ,参数1,参数2)

reduce(函数名/函数表达式(lambda等)/....  ,参数1)

区别:

  1.参数:reduce除了函数外只允许一个参数,而map允许两个

  2.方式:map是将两个参数的每一对值依次放入指定的函数中去,而reduce则是像水车一样一个一个灌入。

      map:

      reduce:(图片偷自这里)

        

    3.比较

    

    4.函数结果:map通常得到的是一个序列,而reduce则是得到一个数值

原文地址:https://www.cnblogs.com/yinsua/p/4548055.html