转载于:https://www.cnblogs.com/huchong/p/9309433.html
比如,有时候,我们需要将列表中的元素,按照每5个分组,分成好几个组时,可以采用下面的代码
a = [1,2,3,4,5,6,7,8,9,10,11]
step = 5
b = [a[i:i+step] for i in range(0,len(a),step)]
print(b)
结果如下:
[[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11]]
https://www.cnb...
(undefined→中文)(0.372 秒)
https://www.cnblogs.com/huchong/p/9309433.html