zoukankan      html  css  js  c++  java
  • python3中内置函数map 和 reduce函数的使用

    # map
    
    """
        map(func, *iterables) --> map object
        
        Make an iterator that computes the function using arguments from
        each of the iterables.  Stops when the shortest iterable is exhausted.
        """
    
        参数:接收一个函数和一个可迭代对象
        返回map对象,本质是一个迭代器
    eg:
        def fun(x):
            return x * x
        map(fun,[1,2,3,4,5])
    # reduce
    
     """
        reduce(function, sequence[, initial]) -> value
        
        Apply a function of two arguments cumulatively to the items of a sequence,
        from left to right, so as to reduce the sequence to a single value.
        For example, reduce(lambda x, y: x+y, [1, 2, 3, 4, 5]) calculates
        ((((1+2)+3)+4)+5).  If initial is present, it is placed before the items
        of the sequence in the calculation, and serves as a default when the
        sequence is empty.
        """
        将两个参数的函数累加应用于序列的项目,从左到右,以便将序列减少到单个值。
         eg:
    result = reduce(lambda left, right: pd.merge(left, right, how='left', on=['store_id','item_id']),
                     pd_list)        
  • 相关阅读:
    操作系统的发展史
    多线程的些许理解(平台x86,具体考虑linux,windows)
    C++ 11 智能指针
    C++虚函数和纯虚函数
    Qt之excel 操作使用说明
    查找之二叉排序树
    图的一些总结
    树的一些总结
    直接插入排序
    冒泡和选择排序
  • 原文地址:https://www.cnblogs.com/songxiaohua/p/9382243.html
Copyright © 2011-2022 走看看