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


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

Re: collections Counter most_common method

Started byPeter Otten <__peter__@web.de>
First post2013-12-14 20:42 +0100
Last post2013-12-14 20:42 +0100
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: collections Counter most_common method Peter Otten <__peter__@web.de> - 2013-12-14 20:42 +0100

#61912 — Re: collections Counter most_common method

FromPeter Otten <__peter__@web.de>
Date2013-12-14 20:42 +0100
SubjectRe: collections Counter most_common method
Message-ID<mailman.4122.1387050131.18130.python-list@python.org>
Mark Lawrence 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.

As Counter is currently a dict you have to look at all items to find the 
most common. With that underlying data structure I don't see how it could 
make sense to yield the most common items incrementally. So

(1) When would you prefer it over the the eager variant?
(2) How would you implement it?

By the way, if you can come up with a plausible answer for the second 
question you should aim higher, for lazy heapq.nlargest() and sorted() 
functions...

[toc] | [standalone]


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


csiph-web