博客园站长
这是人类成长进步中记录的每一时刻

 

1、正常写法

>>> from functools import reduce >>> def fn(x, y): ... return x * 10 + y ... >>> reduce(fn, [1, 3, 5, 7, 9]) 得到 13579

2、简写
reduce(lambda x, y: x * 10 + y,[1, 3, 5, 7, 9])

 步骤拆解:

  1当x, 3当y 1*10+3 =13
  13当x,5当y 13*10+5=135
  .....最终得到13579

 

posted on 2019-03-19 16:47  dm3344  阅读(238)  评论(0)    收藏  举报