3
$\begingroup$

I cannot find the original post now, but I'm quite sure that there's an amazing post teaching us how to do Thread on ragged lists.

But my problem is how to inverse this action?

For example, you can use this customized version of Thread:

MyThread[l1_,l2_]=If[Length@l1==Length@l2!=0,MapThread[MyThread, {l1, l2}],{l1,l2}]

MyThread[{{1, 2}, {2, 3}, {5, 6}}, {{1}, {2, 3}, {{3, 4}, {4, 5}}}]
{{{1, 2}, {1}}, {{2, 2}, {3, 3}}, {{5, {3, 4}}, {6, {4, 5}}}}

But now I get the result and would like to reverse it into two lists(of course you can change it to a thread of 3 or more). The key I think is that at some part of the structure there'll be only two element and that'll be the place to seperate.

Also, If this is too difficult or impossible theoretically, I have another simplified version:

I know that at the bottom level there's only two element while the latter one is an atom expression. e.g. {{{1, 2}, False}, {{2, False}, {3, False}}, {{5, False}, {6, True}}}

How to make this back to its original form?

The desired result will be:
{{{1, 2}, {2, 3}, {5, 6}},{False,{False,False},{False,True}}}

$\endgroup$
4
$\begingroup$
list={{{1,2},{1}},{{2,2},{3,3}},{{5,{3,4}},{6,{4,5}}}};    
Transpose[If[Quiet[Check[Transpose[#],True]]===True,#,Transpose[#]]&/@list]

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

$\endgroup$
  • $\begingroup$ OMG, That is awesome! $\endgroup$ – Wjx Jun 24 '16 at 23:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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