diff -r cf50a352fe22 Lib/heapq.py --- a/Lib/heapq.py Sun Sep 30 04:01:31 2012 +0200 +++ b/Lib/heapq.py Mon Oct 01 21:38:32 2012 +1000 @@ -376,12 +376,22 @@ # When key is none, use simpler decoration if key is None: it = zip(iterable, count()) # decorate + # If input is list, make the decorated iterable a list, as _nsmallest + # contains useful optimizations for lists. + if hasattr(iterable, '__len__'): + it = list(it) result = _nsmallest(n, it) return [r[0] for r in result] # undecorate # General case, slowest method in1, in2 = tee(iterable) it = zip(map(key, in1), count(), in2) # decorate + + # If input is list, make the decorated iterable a list, as _nsmallest + # contains useful optimizations for lists. + if hasattr(iterable, '__len__'): + it = list(it) + result = _nsmallest(n, it) return [r[2] for r in result] # undecorate diff -r cf50a352fe22 Misc/ACKS --- a/Misc/ACKS Sun Sep 30 04:01:31 2012 +0200 +++ b/Misc/ACKS Mon Oct 01 21:38:32 2012 +1000 @@ -154,6 +154,7 @@ Jean Brouwers Gary S. Brown Titus Brown +Will Haldean Brown Oleg Broytmann Dave Brueck Francisco Martín Brugué