1
$\begingroup$

So this does what I want:

#1 <> #2 &["♠", "A"]

♠A

The output is fine. How do I quickly apply this to the list

{{"♠", "A"}, {"♢", "A"}, {"♣", "A"}, {"♡", "A"}}

So that I can combined all of the suits with the Aces? I have tried a mixture of "/", "@" and "/@". None of these worked.

enter image description here

$\endgroup$
3
  • 4
    $\begingroup$ You want @@@ -- apply at level 1. $\endgroup$ – jjc385 Nov 4 '17 at 7:06
  • $\begingroup$ @jjc385 THANKS! Finally, I got it! (#1 <> ToString[#2] &) @@@ carddeck $\endgroup$ – Chen Stats Yu Nov 4 '17 at 7:11
  • $\begingroup$ Happy to help. Note that if carddeck is a nested list like the list given in the question (with all sublist elements being strings), you shouldn't need the ToString in there. $\endgroup$ – jjc385 Nov 4 '17 at 7:17
4
$\begingroup$

You want to Apply your function at level 1 in the list :

#1 <> #2 & @@@ {{"♠", "A"}, {"♢", "A"}, {"♣", "A"}, {"♡", "A"}}
{"♠A", "♢A", "♣A", "♡A"}

As mentioned at the very top of the docs for Apply, f @@@ expr is is syntactic sugar for Apply[ f, expr, {1} ], and has the same effect as Apply[ f, # ]& /@ expr.


Note that #1 <> #2 & parses as StringJoin[#1,#2]&, for which you might as well just use StringJoin :

StringJoin @@@ {{"♠", "A"}, {"♢", "A"}, {"♣", "A"}, {"♡", "A"}}
{"♠A", "♢A", "♣A", "♡A"}
$\endgroup$

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