7
$\begingroup$

I would like to modify the following List:

vtable ={ { {0,{0}},{0, {1}}} ,{{1,{0}},{1,{1}}}  }

as follows:

vtable={{0,0},{0,1},{1,0},{1,1}}

that is I want to remove the far most internal bracket of the list....

I read about the Flatten command but I cannot do much...actually what I get is something like {{0,{0}},{0,{1}}, ....} or even worse... {0,0,0,1,1,0,1,1}

How can I do that? Thanks for your time.

$\endgroup$
13
$\begingroup$

Try with:

Flatten /@ Flatten[vtable, 1]

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

$\endgroup$
14
$\begingroup$
Flatten /@ (Join @@ vtable)

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

ArrayReshape[vtable, {4, 2}]

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

Join @@ vtable /. {a_} :> a

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

MapAt[Sequence @@ # &, vtable, {{All, All, -1}, {1}, {2}}]

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

$\endgroup$
  • $\begingroup$ Thanks for your professional answer but it is for the time being a bit too advanced for me...(+10) $\endgroup$ – dmtri Jan 21 at 9:46
7
$\begingroup$
 vtable /. {x_, {y_}} :> {x, y} // Flatten[#, 1] &

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

$\endgroup$
  • 2
    $\begingroup$ (+1) vtable /. {x_, {y_}} :> {x, y} // Catenate is a (very) slight variant $\endgroup$ – user1066 Jan 21 at 15:27
6
$\begingroup$
Replace[Catenate[vtable], {x_,{y_}}:> {x,y},{1}]

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

$\endgroup$
5
$\begingroup$
Partition[Flatten[vtable],2]

{{0, 0}, {0, 1}, {1, 0}, {1, 1}}

$\endgroup$

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.