Python reduce explanation

后端 未结 5 539
广开言路
广开言路 2020-12-20 21:31

I\'m not able to understand the following code segment:

>>> lot = ((1, 2), (3, 4), (5,))
>>> reduce(lambda t1, t2: t1 + t2, lot)
(1, 2, 3,          


        
5条回答
  •  有刺的猬
    2020-12-20 21:56

    let's trace the reduce

    result = (1,2) + (3,4)

    result = result + (5, )

    Notice that your reduction concatenates tuples.

提交回复
热议问题