Break a list into chunks of size N

my_list = ['python', 'for', 'engineers', 'like',

'complete','solution', 'for', 'python',

'related','queries']

def divide_chunks(l, n):

for i in range(0, len(l), n):

yield l[i:i + n]

n = 5

x = list(divide_chunks(my_list, n))

print (x)


Matrix creation of n*n Using next() + itertools.count()

import itertools

N = 4

print("The dimension : " + str(N))

temp = itertools.count(1)

res = [[next(temp) for i in range(N)] for i in range(N)]

print("The created matrix of N * N: " + str(res))