Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

n largest python

import heapq

nums = [1, 2, 3, 4, 5, 6]

print(heapq.nlargest(3, nums))
# [6, 5, 4]
print(sorted(nums, reverse=True)[:3])
# [6, 5, 4]
print(heapq.nsmallest(3, nums))
# [1, 2, 3]
 
PREVIOUS NEXT
Tagged: #largest #python
ADD COMMENT
Topic
Name
7+4 =