Answer to Question #316830 in Python for MODE

Question #316830

Mode

given a list of integers,write a program to print the mode.

mode - the most common value in the list. if multiple elements with same frequency are present, print all values with same frequency in increasing order.


input

the input will be a single line of containing space-separated integers.


output

the third line of output should contain the mode.

see sample input/output for the output format


explanation 


for example, if the given list of integers are 

2 4 5 6 7 8 2 4 5 2 3 8

the average of all the numbers is 4.67.

after sorting the array,

2 2 2 3 4 4 5 6 7 8 8

as 2 is most repeated number , the mode will be 2.

so the output should be

Mode: 2


sample input 1

2 4 5 6 7 8 2 4 5 2 3 8

sample output 1

Mode: 2



1
Expert's answer
2022-03-26T15:29:54-0400
from collections import Counter
arr = input(">> ").split(" ")
c = Counter(arr)
print("Mode: " + c.most_common(1)[0][0])

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS