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]
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]
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))
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]))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us