Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #61910 > unrolled thread

collections Counter most_common method

Started byMark Lawrence <breamoreboy@yahoo.co.uk>
First post2013-12-14 18:54 +0000
Last post2013-12-14 14:37 -0500
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  collections Counter most_common method Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-14 18:54 +0000
    Re: collections Counter most_common method Roy Smith <roy@panix.com> - 2013-12-14 14:37 -0500

#61910 — collections Counter most_common method

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2013-12-14 18:54 +0000
Subjectcollections Counter most_common method
Message-ID<mailman.4121.1387047279.18130.python-list@python.org>
This method returns a list, the example from The Fine Docs being:-

 >>> Counter('abracadabra').most_common(3)
[('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.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask 
what you can do for our language.

Mark Lawrence

[toc] | [next] | [standalone]


#61911

FromRoy Smith <roy@panix.com>
Date2013-12-14 14:37 -0500
Message-ID<roy-51C15C.14371414122013@news.panix.com>
In reply to#61910
In article <mailman.4121.1387047279.18130.python-list@python.org>,
 Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:

> This method returns a list, the example from The Fine Docs being:-
> 
>  >>> Counter('abracadabra').most_common(3)
> [('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.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web