5
$\begingroup$

This must be easy but I'm stuck, I want to create this row:

{< 1 >}{< 4 >}{< 4 >}{< 22 >}{< 3 >}{< 12 >}{< 54 >}{< 65 >}

from this list

t = {1, 4, 4, 22, 3, 12, 54, 65};

I tried many things like

d = "{<" t[[i]] ">}";
t = {1, 4, 4, 22, 3, 12, 54, 65};
Row[Table[d, {i, 1, 8}]]

but nothing works

$\endgroup$

3 Answers 3

5
$\begingroup$
t = {1, 4, 4, 22, 3, 12, 54, 65}

Other ways:

StringRiffle[t, {"{<", ">}{<", ">}"}]


StringJoin[StringTemplate@"{<``>}" /@ t]

And similar but not the same:

Row[List /@ Skeleton /@ t]

enter image description here

$\endgroup$
2
  • $\begingroup$ The second one is a very good approach because I can manipulate/change the pattern easily $\endgroup$
    – ZaMoC
    Commented May 8, 2017 at 11:37
  • $\begingroup$ @Kuba thanks for introducing me to StringRiffle...guess I should have known about it...:) $\endgroup$
    – ubpdqn
    Commented May 8, 2017 at 11:39
2
$\begingroup$

Perhaps:

t = {1, 4, 4, 22, 3, 12, 54, 65};
a = ">}{<"
Row[{"{<"}~Join~Riffle[t, a]~Join~{">}"}]

or

l = "{<";
r = ">}";
Row[{l, ##, r} & @@ Riffle[t, Row[{r, l}]]]
$\endgroup$
2
$\begingroup$

In:

(*Method 1*)
xs = {1, 4, 4, 22, 3, 12, 54, 65};
box = Function[x, "{<" ~~ ToString[x] ~~ ">}", Listable];
StringJoin@box@xs


(*Method 2*)
rules =  {"{" -> "{<", ", " -> ">}{<", "}" -> ">}"}
xs // ToString // StringReplace[#, rules] &

(*Method 3*)
textString = TextString[{#}, ListFormat -> {"{<", "", ">}"}] &;
xs // Map[textString] // StringJoin

Out:

{<1>}{<4>}{<4>}{<22>}{<3>}{<12>}{<54>}{<65>}
{<1>}{<4>}{<4>}{<22>}{<3>}{<12>}{<54>}{<65>}
{<1>}{<4>}{<4>}{<22>}{<3>}{<12>}{<54>}{<65>}
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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