Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../lib64/python3....
File: heapq.py
return [elem for (elem, order) in result]
[500] Fix | Delete
[501] Fix | Delete
# General case, slowest method
[502] Fix | Delete
it = iter(iterable)
[503] Fix | Delete
result = [(key(elem), i, elem) for i, elem in zip(range(n), it)]
[504] Fix | Delete
if not result:
[505] Fix | Delete
return result
[506] Fix | Delete
_heapify_max(result)
[507] Fix | Delete
top = result[0][0]
[508] Fix | Delete
order = n
[509] Fix | Delete
_heapreplace = _heapreplace_max
[510] Fix | Delete
for elem in it:
[511] Fix | Delete
k = key(elem)
[512] Fix | Delete
if k < top:
[513] Fix | Delete
_heapreplace(result, (k, order, elem))
[514] Fix | Delete
top, _order, _elem = result[0]
[515] Fix | Delete
order += 1
[516] Fix | Delete
result.sort()
[517] Fix | Delete
return [elem for (k, order, elem) in result]
[518] Fix | Delete
[519] Fix | Delete
def nlargest(n, iterable, key=None):
[520] Fix | Delete
"""Find the n largest elements in a dataset.
[521] Fix | Delete
[522] Fix | Delete
Equivalent to: sorted(iterable, key=key, reverse=True)[:n]
[523] Fix | Delete
"""
[524] Fix | Delete
[525] Fix | Delete
# Short-cut for n==1 is to use max()
[526] Fix | Delete
if n == 1:
[527] Fix | Delete
it = iter(iterable)
[528] Fix | Delete
sentinel = object()
[529] Fix | Delete
result = max(it, default=sentinel, key=key)
[530] Fix | Delete
return [] if result is sentinel else [result]
[531] Fix | Delete
[532] Fix | Delete
# When n>=size, it's faster to use sorted()
[533] Fix | Delete
try:
[534] Fix | Delete
size = len(iterable)
[535] Fix | Delete
except (TypeError, AttributeError):
[536] Fix | Delete
pass
[537] Fix | Delete
else:
[538] Fix | Delete
if n >= size:
[539] Fix | Delete
return sorted(iterable, key=key, reverse=True)[:n]
[540] Fix | Delete
[541] Fix | Delete
# When key is none, use simpler decoration
[542] Fix | Delete
if key is None:
[543] Fix | Delete
it = iter(iterable)
[544] Fix | Delete
result = [(elem, i) for i, elem in zip(range(0, -n, -1), it)]
[545] Fix | Delete
if not result:
[546] Fix | Delete
return result
[547] Fix | Delete
heapify(result)
[548] Fix | Delete
top = result[0][0]
[549] Fix | Delete
order = -n
[550] Fix | Delete
_heapreplace = heapreplace
[551] Fix | Delete
for elem in it:
[552] Fix | Delete
if top < elem:
[553] Fix | Delete
_heapreplace(result, (elem, order))
[554] Fix | Delete
top, _order = result[0]
[555] Fix | Delete
order -= 1
[556] Fix | Delete
result.sort(reverse=True)
[557] Fix | Delete
return [elem for (elem, order) in result]
[558] Fix | Delete
[559] Fix | Delete
# General case, slowest method
[560] Fix | Delete
it = iter(iterable)
[561] Fix | Delete
result = [(key(elem), i, elem) for i, elem in zip(range(0, -n, -1), it)]
[562] Fix | Delete
if not result:
[563] Fix | Delete
return result
[564] Fix | Delete
heapify(result)
[565] Fix | Delete
top = result[0][0]
[566] Fix | Delete
order = -n
[567] Fix | Delete
_heapreplace = heapreplace
[568] Fix | Delete
for elem in it:
[569] Fix | Delete
k = key(elem)
[570] Fix | Delete
if top < k:
[571] Fix | Delete
_heapreplace(result, (k, order, elem))
[572] Fix | Delete
top, _order, _elem = result[0]
[573] Fix | Delete
order -= 1
[574] Fix | Delete
result.sort(reverse=True)
[575] Fix | Delete
return [elem for (k, order, elem) in result]
[576] Fix | Delete
[577] Fix | Delete
# If available, use C implementation
[578] Fix | Delete
try:
[579] Fix | Delete
from _heapq import *
[580] Fix | Delete
except ImportError:
[581] Fix | Delete
pass
[582] Fix | Delete
try:
[583] Fix | Delete
from _heapq import _heapreplace_max
[584] Fix | Delete
except ImportError:
[585] Fix | Delete
pass
[586] Fix | Delete
try:
[587] Fix | Delete
from _heapq import _heapify_max
[588] Fix | Delete
except ImportError:
[589] Fix | Delete
pass
[590] Fix | Delete
try:
[591] Fix | Delete
from _heapq import _heappop_max
[592] Fix | Delete
except ImportError:
[593] Fix | Delete
pass
[594] Fix | Delete
[595] Fix | Delete
[596] Fix | Delete
if __name__ == "__main__":
[597] Fix | Delete
[598] Fix | Delete
import doctest # pragma: no cover
[599] Fix | Delete
print(doctest.testmod()) # pragma: no cover
[600] Fix | Delete
[601] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function