collections Counter most_common method

M

Mark Lawrence

This method returns a list, the example from The Fine Docs being:-
[('a', 5), ('r', 2), ('b', 2)]

With the trend in Python being more and more towards methods returning
iterators, is there ever likely to be an imost_common method, or has
this been suggested and rejected, or what? I'm really just curious, but
if enough people were to express an interest and it hasn't already been
done, I'd happily raise an enhancement request on the bug tracker.
 
R

Roy Smith

Mark Lawrence said:
This method returns a list, the example from The Fine Docs being:-
[('a', 5), ('r', 2), ('b', 2)]

With the trend in Python being more and more towards methods returning
iterators, is there ever likely to be an imost_common method, or has
this been suggested and rejected, or what? I'm really just curious, but
if enough people were to express an interest and it hasn't already been
done, I'd happily raise an enhancement request on the bug tracker.

The reason to return iterators instead of lists is that it's more
efficient if the list is very long. I would imagine the most common use
cases for most_common() are to pass it a number like 3. You typically
want to find the most common, or the three most common, or maybe the 10
most common. It's rare that people want the 5000 most common.

So, while I suppose returning an iterator might be more efficient in
some cases, those cases seem pretty rare.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top