mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue 3051: make pure python code pass the same tests as the C version.
This commit is contained in:
parent
5864c9f26c
commit
8a9c4d9866
2 changed files with 9 additions and 16 deletions
|
@ -212,11 +212,10 @@ def nsmallest(n, iterable):
|
|||
pop = result.pop
|
||||
los = result[-1] # los --> Largest of the nsmallest
|
||||
for elem in it:
|
||||
if los <= elem:
|
||||
continue
|
||||
insort(result, elem)
|
||||
pop()
|
||||
los = result[-1]
|
||||
if elem < los:
|
||||
insort(result, elem)
|
||||
pop()
|
||||
los = result[-1]
|
||||
return result
|
||||
# An alternative approach manifests the whole iterable in memory but
|
||||
# saves comparisons by heapifying all at once. Also, saves time
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue