{"id":16152,"date":"2021-08-12T09:36:55","date_gmt":"2021-08-12T04:06:55","guid":{"rendered":"https:\/\/python-programs.com\/?p=16152"},"modified":"2021-11-22T18:38:26","modified_gmt":"2021-11-22T13:08:26","slug":"python-program-to-get-the-position-of-max-value-in-a-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-get-the-position-of-max-value-in-a-list\/","title":{"rendered":"Python Program to Get the Position of Max Value in a List"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Find Vertex, Focus and Directrix of Parabola<\/a> max() is a built-in function that returns the maximum value in a list.<\/p>\n index() function:<\/strong><\/p>\n This function searches the lists. It returns the index where the value is found when we pass it as an argument that matches the value in the list. If no value is found, Value Error is returned.<\/p>\n Given a list, the task is to Get the position of Max Value in a List.<\/p>\n Examples:<\/strong><\/p>\n Example 1 :<\/strong><\/p>\n Input :<\/strong><\/p>\n Output:<\/strong><\/p>\n Example 2 :<\/strong><\/p>\n Input :\u00a0<\/strong><\/p>\n Output:<\/strong><\/p>\n Below are the ways to Get the Position of Max value in a List.<\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Here we printed the index of the maximum element of the given list.<\/p>\n Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Find Vertex, Focus and Directrix of Parabola max() function : max() is a built-in function that returns the maximum value in a list. index() function: This function searches the lists. It returns the index where the value is found when we pass it as an …<\/p>\n
\nmax() function :<\/strong><\/p>\nGiven List = [1, 5, 9, 2, 7, 3, 8]<\/pre>\n
Maximum Value in the above Given list = 9\r\nPosition of Maximum value of the above Given List = 3<\/pre>\n
Given List = [4, 3, 7, 1, 2, 8, 9]<\/pre>\n
Maximum Value in the above Given list = 9\r\nPosition of Maximum value of the above Given List = 7<\/pre>\n
Program to Get the Position of Max Value in a List<\/h2>\n
\n
Method #1: Using Max(),Index() functions\u00a0 (Static Input)<\/h3>\n
\n
# Give the List as static input and store it in a variable.\r\nGvn_lst = [1, 5, 9, 2, 7, 3, 8]\r\n# Get the maximum value of the given list using the built-in max() function and\r\n# store it in another variable\r\nmaxim_vle = max(Gvn_lst)\r\n# Print the maximum value of the above given List.\r\nprint(\"Maximum Value in the above Given list = \", maxim_vle)\r\n# Get the position of the maximum value of the List using the built-in index() function\r\n# and store it in another variable.\r\nmaxim_positn = Gvn_lst.index(maxim_vle)\r\n# Print the position of the maximum value of the given List i.e. maximum position+1\r\n# ( since list index starts from zero).\r\nprint(\"Position of Maximum value of the above Given List = \", maxim_positn+1)\r\n<\/pre>\n
Maximum Value in the above Given list = 9\r\nPosition of Maximum value of the above Given List = 3<\/pre>\n
Method #2: Using Max(),Index() functions\u00a0 (User Input)<\/h3>\n
\n
#Give the list as User input using list(),map(),input(),and split() functions and store it in a variable.\r\nGvn_lst = list(map(int, input('Enter some random List Elements separated by spaces = ').split()))\r\n# Get the maximum value of the given list using the built-in max() function and\r\n# store it in another variable\r\nmaxim_vle = max(Gvn_lst)\r\n# Print the maximum value of the above given List.\r\nprint(\"Maximum Value in the above Given list = \", maxim_vle)\r\n# Get the position of the maximum value of the List using the built-in index() function\r\n# and store it in another variable.\r\nmaxim_positn = Gvn_lst.index(maxim_vle)\r\n# Print the position of the maximum value of the given List i.e. maximum position+1\r\n# ( since list index starts from zero).\r\nprint(\"Position of Maximum value of the above Given List = \", maxim_positn+1)\r\n<\/pre>\n
Enter some random List Elements separated by spaces = 4 3 7 1 2 8 9\r\nMaximum Value in the above Given list = 9\r\nPosition of Maximum value of the above Given List = 7<\/pre>\n
\n