fork(3) download
  1. def chunks(lista, n):
  2. for i in range(0, len(lista), n):
  3. yield lista[i:i + n]
  4.  
  5. l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]
  6. print(list(chunks(l, 3)))
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11], [12, 13, 14]]