Python——functools

该模块为高阶函数提供支持——作用于或返回函数的函数被称为高阶函数。在该模块看来,一切可调用的对象均可视为本模块中所说的“函数”。

reduce:

      #2.使用functools.reduce,要是整数就累加;

               >>>print (reduce(lambda x,y: x+y, [2,3,4]))

         >>>9
      #3.使用functools.reduce,要是字符串、列表、元祖就拼接(相当脱了一层外套)

              >>>print (reduce(lambda x,y: x+y, [[1,2],[3,4]]))

             >>>[1, 2, 3, 4]

原文地址:https://www.cnblogs.com/ting152/p/12510210.html