Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

n-largest and n-smallest in list in python

import heapq

grades = [110, 25, 38, 49, 20, 95, 33, 87, 80, 90]

print(heapq.nlargest(3, grades))
print(heapq.nsmallest(4, grades))

[110, 95, 90]
[20, 25, 33, 38]
 
PREVIOUS NEXT
Tagged: #list #python
ADD COMMENT
Topic
Name
3+9 =