Search
 
SCRIPT & CODE EXAMPLE
 

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]
Comment

PREVIOUS NEXT
Code Example
Python :: how to add a list to a list python 
Python :: python heroku 
Python :: get value of a list of dictionary matching key 
Python :: django froms 
Python :: tokens in python 
Python :: python wikipedia 
Python :: pyplot save image 
Python :: python move 
Python :: wikipedia api python 
Python :: python encryption program 
Python :: how to add colors in python 
Python :: create a pandas dataframe 
Python :: docker python 3.11 
Python :: join python 
Python :: do while in python 
Python :: how to create a for loop in python 
Python :: add an index column in range dataframe 
Python :: sum in python 
Python :: how to access variable of one function in another function in python 
Python :: python return 
Python :: false python 
Python :: pandas read_csv drop column 
Python :: python get all numbers between two numbers 
Python :: how to create a subset of a dataframe in python 
Python :: Simple example of python strip function 
Python :: beautifulsoup docs 
Python :: raspbian run a python script at startup 
Python :: thresholding with OpenCV 
Python :: dataframe cut 
Python :: armstrong number function 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =