如何用python求list中奇数位的元素, 累积和, 还有各数位上的值

2025-04-08 15:33:41
推荐回答(1个)
回答(1):

1

>>> [0,1,2,3,4,5][1::2]
[1, 3, 5]

2

>>> from itertools import accumulate
>>> list(accumulate([1,1,1]))
[1, 2, 3]
>>> list(accumulate([1,-1,3]))
[1, 0, 3]

3

>>> list(map(int,str(123)))
[1, 2, 3]