I have two lists which I would like to combine. One is of a random structure, which might be:
l1={{3, 2, 4, 2}, {2, 3}, {4, 3}, {{2, 2}}, {{3, 3}}, {3, 2}}
where the elements in each sublist may themselves be numbers, or lists.
From this, I create a list given by:
l2=Join[{0}, Accumulate[Flatten[l1, 1]]]
which gives in this case:
{0, 3, 5, 9, 11, 13, 16, 20, 23, {25, 25}, {28, 28}, {31, 31}, {33, 33}}
I now want to go through the original list, and append to each entry in that list, an entry from the second, in order, to end up with:
{{{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}}}}
I can do this using a loop, but I would like to find a functional way to write it. I have tried using various map, list and thread commands, but so far have been unable to solve it.