Usage of reduce Python

Source: Internet
Author: User

1. View the usage of reduce

in the Python command viewImportfunctools Help (Functools) to help (functools.reduce) or fromFunctoolsImportreduce Help on built-inchfunction reduceinchmodule _functools:reduce (...) Reduce (function, sequence[, initial])-value Apply A function of arguments cumulatively to the items of a sequence, fromLeft -to-right, as-to-reduce the sequence to a single value. For example, reduce (Lambdax, Y:x+y, [1, 2, 3, 4, 5]) Calculates ( ((1+2) +3) +4) +5). If Initial isPresent, it isplaced before the items of the sequenceinchThe calculation, andserves as a default when the sequence isempty.>>> Reduce (Lambdax, Y:x+y, [1, 2, 3, 4, 5])15>>> Reduce (Lambdax, Y:x*y, [1, 2, 3, 4, 5])120>>>

Usage of reduce Python

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.