Duplicating entry values of a list to match varying number of sublist entries

Let's say I have a list of lists that looks like

abc = {{1,{{1},{2}}},{2,{{3},{4},{5}}},{3,{{2}}}}//TableForm

where the first entry in every row, the one without brackets, is the x-value and the second entries are the corresponding y-values. While my x-value is always one entry, the number of y-values vary in an inconsistent manner.

I want Mathematica to take every single x-value and "duplicate" it corresponding to the number of y-values attached, so I will get a list of coordinates with one x- and one y-value each, like:

abcnew = {{1,1},{1,2},{2,3},{2,4},{2,5},{3,2}}//TableForm

Is there a fast and easy way to do this in Mathematica 4.0 with list manipulation or do I have to combine Count with Padding?

abcnew  = Join @@ (Thread[{#, Join @@ #2}] & @@@ abc) (* or *)
abcnew = Join @@ (Thread[{#[[1]], Flatten[#[[2]]]}] & /@ abc)

{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 2}}

• Awesome, this does the job in the way I needed! Thank you! Feb 16, 2018 at 9:45

Flatten[abc /. {x_Integer, {y : _List ...}} :> Thread[{x, Join@y}], 1]

(* {{{1, 1}, {1, 2}}, {{2, 3}, {2, 4}, {2, 5}}, {{3, 2}}} *)
• This one also works, thank you! Feb 16, 2018 at 9:54
Flatten[Flatten /@ Thread @ # & /@ abc, 1]

{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 2}}

😁 = ## & @@ (♯ |-> {#, ♯}) /@ (## & @@@ #2) & @@@ # &;

😁 @ abc
{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 2}}

abcnew = Map[Function[Reverse[#]],
Map[Function[
List[#[[1]],
Flatten[#[[2]]]]
],
abc]]], 2]]

You can replace #[[1]] with First[#] and #[[2]] with Last[#]. So it would read:

Map[Function[
List[First[#],
Flatten[Last[#]]]
],
abc]]], 2]]

All the function are pre version 4.0. I no longer have that version installed so could not test on that version as some of these function have been updated post version 4. This should not work if attempt to extend past X,Y to something like X,Y,Z; note the use of Partition[data,2].

• Both of this do work, thank you for your help! However, I chose kglr's answer since it's shorter and easier for me to modify for similar constructed lists, sorry. Feb 16, 2018 at 9:51
Catenate[Thread /@ MapAt[Flatten, abc, {All, 2}]]

Using Outer and Level:

abc = {{1, {{1}, {2}}}, {2, {{3}, {4}, {5}}}, {3, {{2}}}};

Outer[List, {First@#}, Last@#] & /@ abc // Level[#, {-2}] &

or

Sequence @@@ Map[Flatten, Thread /@ abc , {-3}]

FlattenAt[#, -1] & /@ Flatten[#, 1] &@(Thread /@ abc)

Result:

{{1, 1}, {1, 2}, {2, 3}, {2, 4}, {2, 5}, {3, 2}}