Combining lists of lists with random structure
This matches your output:
Module[{i = 1},
Map[{#, l2[[i++]]} &, l1, {2}]
]
If you don't need l2
separately you can eliminate the use of Accumulate
entirely with:
Module[{t = 0},
Map[{#, # &[t, t += #]} &, l1, {2}]
]
The inner function # &[t, t += #]
is just a way to AddTo
t
but return the old value of t
. Equivalently: First[{t, t += #}]
.
Also,
l3 = Internal`PartitionRagged[Most@l2, Length /@ l1];
Transpose /@ Transpose[{l1, l3}]
{{{3, 0}, {2, 3}, {4, 5}, {2, 9}},
{{2, 11}, {3, 13}},
{{4, 16}, {3, 20}},
{{{2, 2}, 23}},
{{{3, 3}, {25, 25}}},
{{3, {28, 28}}, {2, {31, 31}}}}