将python数组拆分为大小相等的块,并在索引处省略元素



我需要迭代0-6、30-36、60-66等的索引,并省略中间索引处的值。

我发现了这样的东西,可以分成相等的块,但没有找到排除特定索引的方法。。。

def chunks(xs, n):
n = max(1, n)
return (xs[i:i+n] for i in range(0, len(xs), n))

有人有暗示吗?

谢谢,祝一切顺利

将函数更改为

def chunks(xs, n):
steps = 30 # you should also give the steps in your case it is 30
n = max(1, n)
return (xs[i:i+n] for i in range(0, len(xs), steps))  # Also this will be returning generator if you want list then use [xs[i:i+n] for i in range(0, len(xs), steps)]