mode of a list python
from collections import Counter
data = Counter(your_list_in_here)
data.most_common() # Returns all unique items and their counts
data.most_common(1) # Returns the highest occurring item
mode of a list python
from collections import Counter
data = Counter(your_list_in_here)
data.most_common() # Returns all unique items and their counts
data.most_common(1) # Returns the highest occurring item
python finding mode of a list
import random
numbers = []
limit = int(input("Please enter how many numbers you would like to compare:n"))
mode =0
for i in range(0,limit):
numbers.append(random.randint(1,10))
maxiumNum = max(numbers)
j = maxiumNum + 1
count = [0]*j
for i in range(j):
count[i]=0
for i in range(limit):
count[numbers[i]] +=1
n = count[0]
for i in range(1, j):
if (count[i] > n):
n = count[i]
mode = i
print("This is the mode = "+str(mode))
print("This is the array = "+str(numbers))
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us