Built-in function start value

Source: Internet
Author: User

Ref

http://mp.weixin.qq.com/s?__biz=MjM5NzU0MzU0Nw==&mid=211637608&idx=1&sn= 1aa3d81c2c56fc87533c49f912692742&scene=0&key= Dffc561732c22651a58840064393fadfff612048d19d8fde33d3062e3072d56b15a4c6f3346a0b8fcd142ef0607dbf92&ascene=1 &uin=mji2mtm3mduwma%3d%3d&devicetype=webwx&version=70000001&pass_ticket=z7bdkmf60pputy3aii% 2bxlj2hbvaiwlxhzjoa22y5qv8ugvvf%2bichyrbpeyxp3ksq

The first one is covered, and reduce how to come out so many parameters, especially the last one does not understand

Then tried it:

>>> reduce (Lambda x,y:x+y,range (101), 1)5051

1 should be a starting value, but the next action is to assign the value of 0 to Y to continue, or to assign the value to X to continue, unclear

Apply a function of arguments cumulatively to the items of a sequence,      from Left -to-right, 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).  IS are    placed before the items     in the calculation and  serves as a default    when the is empty.

So far, we've seen enumerate with a starting value.

T=range (Ten) for in enumerate (t,start=1):    print  index,value     1 02 13 24 35 46 57 68 79 810 9

and sum

>>> sum (Range (0,101), 1)5051

Built-in function start value

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.