-2

I have a list of strings like this:

['00000001000000000000000000000000', '11101000000000000000000000000000', '00011000000000000000000000000000', '11001000000000000000000000000000', '00101000000000000000000000000000', '10101000000000000000000000000000']

I want to group it in the chunks of equal lengths:

[['00000001000000000000000000000000', '11101000000000000000000000000000', '00011000000000000000000000000000'], ['11001000000000000000000000000000', '00101000000000000000000000000000', '10101000000000000000000000000000']]

Can any one please help me out?

sashkello
  • 17,306
  • 24
  • 81
  • 109
user3487900
  • 111
  • 1
  • 1
  • 6

1 Answers1

0

Assuming the length of the list is perfectly divisible by arbitrary number N, here is a basic script:

import copy
L = ['000','111','222','333','444','555','666','777','888']
new_L = []

chunk = []
for i, list_item in enumerate(L):
    chunk.append(list_item)
    if (i+1) % N == 0:
        new_L.append(copy.deepcopy(chunk))
        chunk=[] 
Kiran Jain
  • 36
  • 3