2
$\begingroup$

I have a list of strings, like so:

{"aa bb", "cc dd", "aa bb", "aa bb", "cc dd", "ww ss", "ss ss", "kk mm"}

I know WordCounts will return the numbers of every single word, but I want to the word group numbers, i.e., "aa bb" 3 times, and "cc dd" 2 times. How can I do this?

$\endgroup$

closed as off-topic by MarcoB, Carl Lange, Henrik Schumacher, Öskå, march Mar 8 at 17:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – MarcoB, Carl Lange, Henrik Schumacher, Öskå, march
If this question can be reworded to fit the rules in the help center, please edit the question.

8
$\begingroup$

You can try Tally

lst = {"aa bb", "cc dd", "aa bb", "aa bb", "cc dd", "ww ss", "ss ss",   "kk mm"};
Tally[lst]

Mathematica graphics

Edit by m_goldberg

As J.M. says in his comment below, Counts will give the same information as an association.

Counts[data]

<|"aa bb" -> 3, "cc dd" -> 2, "ww ss" -> 1, "ss ss" -> 1, "kk mm" -> 1|>

This is equivalent to

Rule @@@ Tally[data] // Association
$\endgroup$
  • 2
    $\begingroup$ Counts[] should also work. $\endgroup$ – J. M. is away Mar 4 at 5:48

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