2 ms·
> collections.Counter.most_common() uses heapq.nlargest() which is slightly more efficient than a full n*log n sort. Creating a heap is O(n) if I remember corr
by klipt 13y ago
> collections.Counter.most_common() uses heapq.nlargest() which is slightly more efficient than a full n*log n sort.
Creating a heap is O(n) if I remember correctly, so that may well be the most efficient solution.