How to Calculate Mode of List in Python
Posted on: February 23, 2021 by Ariessa Norramli
In this article, you will learn how to calculate the mode of a list in Python.
Let’s say you have a list named ‘a’ with value [1, 2, 1, 3, 2, 2, 1, 3, 4].
a = [1, 2, 1, 3, 2, 2, 1, 3, 4]
In order to calculate the mode of a list, you can use the statistics.mode()
method.
# Import statistics module
import statistics
a = [1, 2, 1, 3, 2, 2, 1, 3, 4]
print(statistics.mode(a))
# => 1
Note: The statistics.mode()
method functions by returning the mode of a supplied list. In statistics, mode
refers to a value that appears the most often in a set of values.
Share on social media
//