We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 55bec89 commit 073d935Copy full SHA for 073d935
Lib/collections/__init__.py
@@ -27,7 +27,6 @@
27
]
28
29
import _collections_abc
30
-import heapq as _heapq
31
import sys as _sys
32
33
from itertools import chain as _chain
@@ -608,7 +607,10 @@ def most_common(self, n=None):
608
607
# Emulate Bag.sortedByCount from Smalltalk
609
if n is None:
610
return sorted(self.items(), key=_itemgetter(1), reverse=True)
611
- return _heapq.nlargest(n, self.items(), key=_itemgetter(1))
+
+ # Lazy import to speedup Python startup time
612
+ import heapq
613
+ return heapq.nlargest(n, self.items(), key=_itemgetter(1))
614
615
def elements(self):
616
'''Iterator over elements repeating each as many times as its count.
0 commit comments