请问不定数量(LEN)的 list,一次取 INTERVAL 个值为一组,不足自成一组
要么写比较简洁?(下面写法不对,只能跑3个一组)
LEN = 100
INTERVAL = 3
lst = [x for x in range(0, LEN)]
for i in range(0, LEN, INTERVAL):
try:
print(lst[i], lst[i+1], lst[i+2])
except IndexError:
try:
print(lst[i], lst[i+1])
except IndexError:
print(lst[i])