Sometimes, while working with Mathematics, we can have a problem in which we intend to compute the standard deviation of a sample. This has many applications in competitive programming as well as school level projects. Let’s discuss certain ways in which this task can be performed.

**Method #1 : Using sum() + list comprehension**

This is a brute force shorthand to perform this particular task. We can approach this problem in sections, computing mean, variance and standard deviation as square root of variance. The

`sum()`

is key to compute mean and variance. List comprehension is used to extend the common functionality to each of element of list.
`# Python3 code to demonstrate working of ` `# Standard deviation of list ` `# Using sum() + list comprehension ` ` ` `# initializing list ` `test_list ` `=` `[` `4` `, ` `5` `, ` `8` `, ` `9` `, ` `10` `] ` ` ` `# printing list ` `print` `(` `"The original list : "` `+` `str` `(test_list)) ` ` ` `# Standard deviation of list ` `# Using sum() + list comprehension ` `mean ` `=` `sum` `(test_list) ` `/` `len` `(test_list) ` `variance ` `=` `sum` `([((x ` `-` `mean) ` `*` `*` `2` `) ` `for` `x ` `in` `test_list]) ` `/` `len` `(test_list) ` `res ` `=` `variance ` `*` `*` `0.5` ` ` `# Printing result ` `print` `(` `"Standard deviation of sample is : "` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output :**

The original list : [4, 5, 8, 9, 10] Standard deviation of sample is : 2.3151673805580453

**Method #2 : Using pstdev()**

This task can also be performed using inbuilt functionality of

`pstdev()`

. This function computes standard deviation of sample internally.
`# Python3 code to demonstrate working of ` `# Standard deviation of list ` `# Using pstdev() ` `import` `statistics ` ` ` `# initializing list ` `test_list ` `=` `[` `4` `, ` `5` `, ` `8` `, ` `9` `, ` `10` `] ` ` ` `# printing list ` `print` `(` `"The original list : "` `+` `str` `(test_list)) ` ` ` `# Standard deviation of list ` `# Using pstdev() ` `res ` `=` `statistics.pstdev(test_list) ` ` ` `# Printing result ` `print` `(` `"Standard deviation of sample is : "` `+` `str` `(res)) ` |

*chevron_right*

*filter_none*

**Output :**

The original list : [4, 5, 8, 9, 10] Standard deviation of sample is : 2.3151673805580453

## Recommended Posts:

- Absolute Deviation and Absolute Mean Deviation using NumPy | Python
- Calculate the average, variance and standard deviation in Python using NumPy
- Create the Mean and Standard Deviation of the Data of a Pandas Series
- How to Plot Mean and Standard Deviation in Pandas?
- Compute the mean, standard deviation, and variance of a given NumPy array
- Python | Pandas Series.mad() to calculate Mean Absolute Deviation of a Series
- Interquartile Range and Quartile Deviation using NumPy and SciPy
- Inplace vs Standard Operators in Python
- Python program to represent floating number as hexadecimal by IEEE 754 standard
- Standard GUI Unit Converter using Tkinter in Python
- Python | Convert list of string to list of list
- Python | Convert list of tuples to list of list
- Python | Convert List of String List to String List
- Python | Maximum sum of elements of list in a list of lists
- Sort the values of first list using second list in Python
- Python List Comprehension | Segregate 0's and 1's in an array list
- Python | Pair and combine nested list to tuple list
- Python | Filter a list based on the given list of strings
- Python | Convert a nested list into a flat list
- Python program to create a list of tuples from given list having number and its cube in each tuple

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.