DEV Community

Pan Chasinga
Pan Chasinga

Posted on

1

Answer: Sorting a counter (and extracting the most common values)

To update this question, I'm using Julia v1.2.1 and there is no select! afaik.

Here is a slight modification to @Toivo's implementation I used:

using DataStructures

most_common(c::Accumulator) = most_common(c, length(c))
most_common(c::Accumulator, k) = sort(collect(c), by=kv->kv[2], rev=true)[1:k]

This returns an ::Array{Pair{String,Int}},1 with k members which is similar to Python Counter.most_common(k) which…

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up