![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Mean deviation of Elements
When it is required to find the mean deviation of the elements of a list, the ‘sum’ method and the ‘len’ method is used.
Example
Below is a demonstration of the same
my_list = [3, 5, 7, 10, 12] print("The list is :") print(my_list) my_mean = sum(my_list) / len(my_list) my_variance = sum([((x – my_mean) ** 2) for x in my_list]) / len(my_list) my_result = my_variance ** 0.5 print("The result is :") print(result)
Output
The original list : [3, 5, 7, 10, 12] the standard deviation of list is : 3.2619012860600183
Explanation
A list is defined and is displayed on the console.
The ‘sum’ of the list and the ‘len’ of the list is obtained.
The ‘sum’ is divided by the ‘len’.
This is assigned to a variable.
Now, the elements in the list are iterated and squared.
Their sum is obtained and assigned to another variable.
The square root of the above variable is obtained and assigned to a ‘result’.
This is the output that is displayed on the console.
Advertisements