culTest

    One of the 50 questions in this topic

    How much do you know about Python?

    What does the reduce() function do in Python?

    Answers

    Reduce the size of a list by removing elements
    Applies a cumulative function to the elements of an iterableCorrect
    Simplify complex mathematical expressions
    Compress data to save memory

    reduce() (from the functools module) applies a cumulative function to the elements of an iterable from left to right, reducing the sequence to a single value. For example: reduce(lambda x, y: x + y, [1, 2, 3, 4]) calculates ((1+2)+3)+4 = 10. Unlike map() and filter(), reduce() is not in the global namespace in Python 3, reflecting Guido van Rossum's preference for more explicit constructs such as for loops.