
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to find Maximum and minimum element’s position in a list?
In python is very easy to find out maximum, minimum element and their position also. Python provides different inbuilt function. min() is used for find out minimum value in an array, max() is used for find out maximum value in an array. index() is used for finding the index of the element.
Algorithm
maxminposition(A, n) /* A is a user input list and n is the size of the list.*/ Step 1: use inbuilt function for finding the position of minimum element. A.index(min(A)) Step 2: use inbuilt function for finding the position of a maximum element. A.index(max(A))
Example Code
# Function to find minimum and maximum position in list def maxminposition(A, n): # inbuilt function to find the position of minimum minposition = A.index(min(A)) # inbuilt function to find the position of maximum maxposition = A.index(max(A)) print ("The maximum is at position::", maxposition + 1) print ("The minimum is at position::", minposition + 1) # Driver code A=list() n=int(input("Enter the size of the List ::")) print("Enter the Element ::") for i in range(int(n)): k=int(input("")) A.append(k) maxminposition(A,n)
Output
Enter the size of the List ::4 Enter the Element:: 12 34 1 66 The maximum is at position:: 4 The minimum is at position:: 3
- Related Articles
- Java program to find Maximum and minimum element’s position in a list
- Python Program to Get Minimum and Maximum from a List
- Python program to find the maximum and minimum value node from a doubly linked list
- Python program to find the maximum and minimum value node from a circular linked list
- Java Program to Get Minimum and Maximum From a List
- Program to find average salary excluding the minimum and maximum salary in Python
- Program to find minimum steps to reach target position by a chess knight in Python
- Program to find minimum possible maximum value after k operations in python
- Program to find minimum number of hops required to reach end position in Python
- Program to find minimum cost to reduce a list into one integer in Python
- Program to Find Out the Maximum Final Power of a List in Python
- Program to find minimum total cost for equalizing list elements in Python
- 8085 program to find maximum and minimum of 10 numbers
- Find minimum and maximum elements in singly Circular Linked List in C++
- Write a Python program to trim the minimum and maximum threshold value in a dataframe

Advertisements