怎样在最小误差内把数字区间平均分成100份,末尾等

2025-04-05 06:19:02
推荐回答(1个)
回答1:

怎样在最小误差内把数字区间平均分成100份,末尾等
下面是我取range(1,400)的结果(一小部分):[[1,101,201,301],[2,102,202,302],[3,103,203,303],[4,104,204,304],[5,105,205,305],[6,106,206,306],[7,107,207,307],[8,108,208,308],[9,109,209,309],[10,110,210,310]...].
如果合意的话,代码是这样:
import itertools
def strider(p,n):
result = [ [] for x in itertools.repeat(0,n)]
resiter = itertools.cycle(result)
for item , sublist in itertools.izip(p,resiter):
sublist.append(item)
return result

## test:
p = range(1,400)
a = strider(p,100) #一百份
print a