Three higher-order functions

  1. map 与reduce

    • map()

      • Prototype map (fn, lsd)

        • 1 is a function of the parameter

        • 2 is a list of parameters

      • Features

        • The functions passed successively to each element in the sequence, and to return the result as a new Iterator

    • reduce()

      • Need to import from functools import reduce

      • Prototype reduce (fn, lsd)

        • 1 is a function of the parameter

        • 2 is a list of parameters

      • Function: a function of acting on the sequence, this function must accept two parameters, and the reduce the result of the next element in the sequence continues to cumulative operation

  2. filter()

    • Prototype filter (fn, lsd)

      • 1 as a function parameter

      • 2 is a sequence parameter

    • Function: the sequence for filtering (filter data)

    • Vernacular: The function passed successively to each element of the sequence, according to returns True or False decide whether to keep the element

  3. sorted()

    • Sort: bubble, choose quick sort, insert, counter

    • sorted(lsd,key=)

      • A parameter sequence

      • Parameters 2key to accept function to implement custom sorting rules

    • sorted(lsd,reverse = True)

      • A parameter sequence

      • Descending order parameter 2

Guess you like

Origin www.cnblogs.com/fengzi759/p/12001178.html