fork(1) download
  1. def chunks(lista, n):
  2. inicio = 0
  3. for i in range(n):
  4. final = inicio + len(lista[i::n])
  5. yield lista[inicio:final]
  6. inicio = final
  7.  
  8. l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
  9. 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, 15]]