3 ms·
In this case (Python's collections.Counter[1]), the argument doesn't do what you suggest: you don't return the most common out of the first n items, you return
by beaumartinez 15y ago
In this case (Python's collections.Counter[1]), the argument doesn't do what you suggest: you don't return the most common out of the first n items, you return the n most common items.
I don't know anything of the specifics of partial sorting but if the argument did what you suggest I'd guess the code would have a line like:
# Deal only with the first n items.
items = items[:n]
As it would make the code much simpler (quoting from The Zen Of Python, "special cases aren't special enough to break the rules"—we don't need a partial sort).
[1] http://docs.python.org/library/collections.html#counter-objects http://docs.python.org/library/collections.html#counter-obje...