我有一个庞大的浮点值列表和一小部分浮点值。我想将我的巨大列表分成几个较小的列表,每个列表的长度等于我的小列表的长度。
举个例子,考虑一下:
huge = [1.2,3.0,5.6,8.9,10.7,4.3,7.6,9.8,11.6,13.2,12.8,14.5] # len = 12
small = [1,2,3] # len = 3
numlist = len(huge)/len(small) # 4 sublists in listomega
listomega = [[] for index in range(numlist)] # index = 0,1,2,3
### ????
print(listomega)
>>> [[1.2,3.0,5.6],[8.9,10.7,4.3],[7.6,9.8,11.6],[13.2,12.8,14.5]]
print(listomega[0])
>>> [1.2,3.0,5.6]
我该怎么做呢?
我注意到this answer似乎有一个解决方案,但我无法打印结果。
print(chunks(l, n))
>>> <generator object chunks at 0x10b3f1f68>