Loading

Python实现列表均等分割(每间隔X分割)

代码

a = [1,2,3,4,5,6,7,8,9,10,11]
step = 3
b = [a[i:i+step] for i in range(0,len(a),step)]

效果

>>> b
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11]]

参考

https://blog.csdn.net/mr_cat123/article/details/80584988

posted @ 2020-07-17 09:23  azureology  阅读(3510)  评论(0编辑  收藏  举报