# Convert elements of list to string

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"}}


lis = {{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}};
{First@#, StringJoin[ToString /@ Rest@#]} & /@ lis

(* {{M, "1001110"}, {A, "000"}} *)

• Similarly, {#1, StringJoin @@ ToString /@ {##2}} & @@@ lis. Apr 5, 2016 at 21:38
• @march. That's a good one too. Apr 5, 2016 at 22:02
Cases[{{M, 1, 0, 0, 1, 1, 1, 0}, {A, 0, 0, 0}}, {x_, y__} :> {x,
StringJoin[ToString /@ {y}]}]

• Why RuleDelayed required? (It is, I know; but why?) For example, if the second pattern mapped to just {y}, it would not be required.
– Alan
Apr 5, 2016 at 21:01
• @Alan I assume to keep y from being shadowed by another variable named y Apr 5, 2016 at 22:12
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.