Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python program to find largest number in a list

# Python program to find largest
# number in a list
 
# list of numbers
list1 = [10, 20, 4, 45, 99]
 
# sorting the list
list1.sort()
 
# printing the last element
print("Largest element is:", list1[-1])
Comment

Python program to find N largest elements from a list

# Python program to find N largest
# element from given list of integers
  
# Function returns N largest elements
def Nmaxelements(list1, N):
    final_list = []
  
    for i in range(0, N): 
        max1 = 0
          
        for j in range(len(list1)):     
            if list1[j] > max1:
                max1 = list1[j];
                  
        list1.remove(max1);
        final_list.append(max1)
          
    print(final_list)
  
# Driver code
list1 = [2, 6, 41, 85, 0, 3, 7, 6, 10]
N = 2
  
# Calling the function
Nmaxelements(list1, N)
Comment

PREVIOUS NEXT
Code Example
Python :: python class arbitrary arguments 
Python :: copy dataframe columns names 
Python :: python change function of object 
Python :: conv2 python 
Python :: python __lt__ magic method 
Python :: The datetime and django.utils.timezone modules are available, so you can do e.g. timezone.now 
Python :: is python a programming language 
Python :: Display an image over another image at a particular co-ordinates in openCV 
Python :: python tkinter button dynamic button command 
Python :: Local to ISO 8601: 
Python :: read a csv file in pandas 
Python :: python set python key default 
Python :: how to union value without the same value in numpy 
Python :: how to convert response to beautifulsoup object 
Python :: convert string to number python 
Python :: pyautogui doc 
Python :: django create super user 
Python :: pandas dataframe from list how to make the date column an index 
Python :: download latest chromedriver python code 
Python :: python get text of QLineEdit 
Python :: remove whitespace from data frame 
Python :: py function 
Python :: video steganography using python 
Python :: draw picture in python libraries 
Python :: docstrings in python 
Python :: Get more than one longest word in a list python 
Python :: how to import a class from a file to another python 
Python :: twitter api python 
Python :: q fields django Q objects 
Python :: Sum of Product 1 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =