0

I have a huge list of float values and a small list of float values. I want to break my huge list into several smaller lists with each having a length equal to the length of my small list.

As an example, consider:

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]

How can I go about doing this?

I noticed this answer which seemed to have a solution, though I cannot print the result.

print(chunks(l, n))
>>> <generator object chunks at 0x10b3f1f68>
  • 1
    You need to iterate over the generator.Just use `list(chunks(l,n))` to actually get the list. Go read about generators. This question is a duplicate – juanpa.arrivillaga Feb 27 '17 at 05:00
  • 1
    Possible duplicate of [How do you split a list into evenly sized chunks?](http://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks) – juanpa.arrivillaga Feb 27 '17 at 05:00

0 Answers0