{"id":16043,"date":"2021-09-30T11:00:26","date_gmt":"2021-09-30T05:30:26","guid":{"rendered":"https:\/\/python-programs.com\/?p=16043"},"modified":"2021-11-22T18:35:31","modified_gmt":"2021-11-22T13:05:31","slug":"python-program-to-find-median-of-list","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-find-median-of-list\/","title":{"rendered":"Python Program to Find Median of List"},"content":{"rendered":"

In the previous article, we have discussed Python Program to get the Last Word from a String<\/a><\/p>\n

Median:<\/strong><\/p>\n

In general, the median is the middle value of a sorted list of elements. To find the median, we must first sort the data if it is not already sorted. The middle value can then be extracted and printed. If the number of elements in the list is even, we can calculate the median by taking the average of the list’s two middle values. Else take the middle value.<\/p>\n

For example, let the given list is [ 1, 2, 4, 3, 6, 5].<\/p>\n

The sorted form of the given list is [1, 2, 3, 4, 5, 6].<\/p>\n

The median is the average of the middle two elements i.e.(3+4) \/2<\/strong>. Therefore, the Median is\u00a0 3.5.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:\u00a0<\/strong><\/p>\n

Given List = [ 5, 2, 4 ,2, 1]<\/pre>\n

Output:<\/strong><\/p>\n

The Median of List of Elements = 2<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [9, 6, 1, 4, 5, 2, 7, 8]<\/pre>\n

Output:<\/strong><\/p>\n

The Median of the Given List of Elements = 5.5<\/pre>\n

Program to Find Median of List :<\/h2>\n

Beginners and experienced programmers can rely on these Best Java Programs Examples<\/a> and code various basic and complex logics in the Java programming language with ease.<\/p>\n

Below are the ways to perform to find the median of a List in python.<\/p>\n