-
Notifications
You must be signed in to change notification settings - Fork 262
most_common method for counters #198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| merge(a, a2) # return a new accumulator/counter that combines the | ||
| # values/counts in both a and a2 | ||
|
|
||
| most_common(a) # Return a list of the most common elements and their counts from the most common to the least. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think fixing the indentation here should get rid of the weirdness in the rich diff
|
For parity with Julia Base, it might be nice to create a version of There are related functions, |
|
Could the heap nlargest be extended to take a "by" keyword? |
|
Well, it could. This might not be a good idea if performance is an issue (see http://docs.julialang.org/en/release-0.4/manual/performance-tips/#declare-types-of-keyword-arguments, although there isn't much explanation as to why keywords can be slow). I'm curious what your use case would be, since Another idea, which I like a little better, would be to implement a separate |
|
I think that the users would often want all the values in order, rather than the n most common. And most_common could be somewhat more suitable for this than nlargest. Here is another suggestion:
|
|
It may also be worth special casing Also good idea. I didn't even know this is missing. This is one of the main uses of the Counter type. |
rawls238
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ymer any updates on this? It would be nice to merge this in once some of the comments are resolved
|
Bump. |
|
This seems to have been satisfied by #375 (using |
Return a list of the most common elements in a counter and their counts, ordered from the most common to the least.
most_common(counter([1, 6, 2, 2, 5, 5, 5]))
4-element Array{Pair{Int64,Int64},1}:
5=>3
2=>2
6=>1
1=>1