return largest three numbers of list code example
Example 1: python find in largest 3 numbers in an array
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, ]
result = []
num = int(input('Enter N: '))
for x in range(0, num):
largeNum = 0
for y in range(len(array)):
if array[y] > largeNum:
largeNum = array[y]
array.remove(largeNum)
result.append(largeNum)
print(result)
Example 2: how to find greatest number in python
Method 1 : Sort the list in ascending order and print the last element in the list.
filter_none
edit
play_arrow
brightness_4
list1 = [10, 20, 4, 45, 99]
list1.sort()
print("Largest element is:", list1[-1])
Output:
Largest element is: 99