Append cumulative list of lists python

Use accumulate from itertools:

list(itertools.accumulate(l_Of_l))                                                                                              
Out: 
[[1],
 [1, 2],
 [1, 2, 3],
 [1, 2, 3, 4],
 [1, 2, 3, 4, 5],
 [1, 2, 3, 4, 5, 6],
 [1, 2, 3, 4, 5, 6, 7]]

Leave a Comment