This may be a rather strange question. I will try to create a sort of minimal working example.

Suppose that I have two lists, list1 and list2. Both list1 and list2 are ragged, and they both have multiple levels. However, list1 and list2 have the same number of elements, and their level distributions/arrangements are the same. For example:

list1 = {{{a, b, c}, {d, e, f, g, h}, {i, j}}, {{AA, BB}, {CC, DD, EE}}};
list2 = {{{1, 2, 3}, {4, 5, 6, 7, 8}, {9, 10}}, {{11, 12}, {13, 14, 15}}};

I would like to "thread" or "transpose" list1 and list2 to obtain list3, which has the same basic structure but with corresponding elements paired:

list3 = 
{{{{a, 1}, {b, 2}, {c, 3}}, {{d, 4}, {e, 5}, {f, 6}, {g, 7}, {h, 8}}, {{i, 9}, {j, 10}}},
    {{{AA, 11}, {BB, 12}}, {{CC, 13}, {DD, 14}, {EE, 15}}}}

Is there a relatively simple way to obtain list3 from list1 and list2, apart from using a complicated nesting of Table commands? Transpose, Thread, and MapThread all seem potentially useful, but not entirely straightforward for such "deep," ragged lists. Do you have any suggestions? Thanks for your time.

  • 1
    $\begingroup$ Duplicates: (6102), (9012), (17400) $\endgroup$
    – Mr.Wizard
    Jul 25, 2013 at 16:34
  • $\begingroup$ @Mr.Wizard For this one, my memory has let me down - I was sure this wasn't asked before. Voting to close, then. $\endgroup$ Jul 25, 2013 at 18:06

1 Answer 1


Here is one way:

SetAttributes[add, Listable];
add[x_, y_] := {x, y}

and now

add[list1, list2]

will give you what you want.


Not the answer you're looking for? Browse other questions tagged or ask your own question.