Search
 
SCRIPT & CODE EXAMPLE
 

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

find the largest and smallest numbers in a list

#Exercise 3 -  Find the largest and smallest number in a list
thislist = input("How many numbers do you want to enter:")
newlist = []
for x in range (0, int(thislist)):
 owl = int(input("Please Enter your numbers:"))
 newlist.append(owl)
print ("The max number entered is:", max(newlist))
print ("The min number entered is:", min(newlist))
Comment

find the largest and smallest numbers in a list

thislist = [677,8765,8765,876,470,754,6784,56789,7658,]
thislist.sort()
print ("The smallest number is: " + str(thislist[0]))
print ("The largest number is: " + str(thislist[-1]))
Comment

# find the n smallest and greatest numbers in list

# find the n smallest and greatest numbers in list
import heapq
numbers = [10, 40, 25, 500, 90, 59, 320, 200, 100, 800]
print(heapq.nlargest(4, numbers))
# [800, 500, 320, 200]
import heapq
numbers = [10, 40, 25, 500, 90, 59, 320, 200, 100, 800]
print(heapq.nsmallest(4, numbers))
# [10, 25, 40, 59]
Comment

PREVIOUS NEXT
Code Example
Python :: # generators 
Python :: Find number of triangles that can be made by given sides of triangle 
Python :: for _ in range python 
Python :: Python find permutations of operators between each digit in a given string of digits will result in a particular answer 
Python :: how to use ci variables in python robot 
Python :: list cwd python 
Python :: pd.to_excel header char vertical 
Python :: pairplot yaxis diagonal 
Python :: FizzBuzz in Python Using String Concatenation 
Python :: WS2812 Thonny microPython 
Python :: range function without end value 
Python :: pip install time python 
Python :: Validation using voluptuous python library 
Python :: List Comprehension simple example 
Python :: remap values in a column based on condition from another dataframe 
Python :: scikit learn lazy predict 
Python :: django updateview not saving 
Python :: python create empty list with size 
Python :: difference between iglob() and glob() functions in python 
Python :: Explaining async session in requests-html 
Python :: Python NumPy ndarray flat function Example 
Python :: find duplicate row in python sqlite database 
Python :: Python NumPy require Function Example with requirements attribute 
Python :: configure socketio static file python specific content type 
Python :: How to obtain a jpeg resolution in python 
Python :: NumPy bitwise_and Example When inputs are numbers 
Python :: NumPy bitwise_xor Code When inputs are Boolean 
Python :: qt list widget let editable 
Python :: penggunaan keys di python 
Python :: how can I edit the history in python shell 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =