a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
n = 5
for b in [a[i:i + n] for i in range(0, len(a), n)]:
print(b)
结果如下
LWJdeMacBook-Pro:projTest lai$ python3 test1.py
[1, 2, 3, 4, 5]
[6, 7, 8, 9, 0]
参考https://blog.csdn.net/Mr_Cat123/article/details/80584988学习到的,谢谢博主Mr-Cat伍可猫