def nth_largest(n, iter_list):
"""``O(nlogn)`` time if ``n`` is median.
Better if largest or smallest.
Notes
-----
Adopted and/or modified from reference(s):
FogleBird on stackoverflow.com/questions/1034846/
"""
length = len(iter_list)
if n >= length:
return heapq.nlargest(length, iter_list)[-1]
return heapq.nlargest(n, iter_list)[-1]
# OS utilities
评论列表
文章目录