how easily can I convert elements of this list to string. If I have output like this:
{{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}
And I want something like this:
{{M, 1001110}, {A, 000}}
Or
{{M, "1001110"}, {A, "000"}}
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityhow easily can I convert elements of this list to string. If I have output like this:
{{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}
And I want something like this:
{{M, 1001110}, {A, 000}}
Or
{{M, "1001110"}, {A, "000"}}
lis = {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}};
{First@#, StringJoin[ToString /@ Rest@#]} & /@ lis
(* {{M, "1001110"}, {A, "000"}} *)
{#1, StringJoin @@ ToString /@ {##2}} & @@@ lis
.
$\endgroup$
Cases[{{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}, {x_, y__} :> {x,
StringJoin[ToString /@ {y}]}]
{y}
, it would not be required.
$\endgroup$
y
from being shadowed by another variable named y
$\endgroup$
Transpose[{a[[;; , 1]], StringJoin @@@ IntegerString @ a[[;; , 2 ;;]]}]
If on the off chance you are seeking binary output for numbers then:
dat = {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}};
{First@#, BaseForm[FromDigits[Rest@#, 2], 2]} & /@ dat
Hope this helps.