zip(*[ITER(S)]*n)在Python中是如何工作的?s = [1,2,3,4,5,6,7,8,9]n = 3zip(*[iter(s)]*n) # returns [(1,2,3),(4,5,6),(7,8,9)]如何zip(*[iter(s)]*n)工作?如果它是用更冗长的代码编写的,它会是什么样的呢?
3 回答

慕运维8079593
TA贡献1876条经验 获得超5个赞

临摹微笑
TA贡献1982条经验 获得超2个赞
l = range(9)zip(*([l]*3)) # note: not an iter here, the lists are not emptied as we iterate # output [(0, 0, 0), (1, 1, 1), (2, 2, 2), (3, 3, 3), (4, 4, 4), (5, 5, 5), (6, 6, 6), (7, 7, 7), (8, 8, 8)]
添加回答
举报
0/150
提交
取消