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$
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$
  • $\begingroup$ The second one is a very good approach because I can manipulate/change the pattern easily $\endgroup$ – J42161217 May 8 '17 at 11:37
  • $\begingroup$ @Kuba thanks for introducing me to StringRiffle...guess I should have known about it...:) $\endgroup$ – ubpdqn May 8 '17 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, privacy policy and cookie policy

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