python将一组数分成每3个一组的实例
程序员文章站
2022-06-30 10:18:28
如下所示:
a = [1,2,3,4,5,6,7,8,9,10,11]
step = 3
b = [a[i:i+step] for i in range(0,...
如下所示:
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)] print(b)
结果如下:
[[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11]] >>> b[1] [4, 5, 6]
以上这篇python将一组数分成每3个一组的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。