Skip to content

Commit 9274247

Browse files
authored
Update average_mode.py
1 parent 8579199 commit 9274247

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

maths/average_mode.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
def mode(inputlist): #Defining function "mode."
2-
checklist = inputlist.copy() #Copying inputlist to check with the index number later.
3-
result = list() #Empty list to store the counts of elements in inputlist
1+
def mode(inputlist): #Defining function "mode."
2+
"""
3+
This function returns the mode(Mode as in the measures of central tendency) of the input data.
4+
5+
>>>mode([2,3,4,5,3,4,2,5,2,2,4,2,2,2])
6+
2
7+
8+
the input list may contain any Datastructure or any Datatype.
9+
"""
10+
checklist = inputlist.copy() #Copying inputlist to check with the index number later.
11+
result = list() #Empty list to store the counts of elements in inputlist
412
for x in inputlist:
513
result.append(inputlist.count(x))
614
inputlist.remove(x)
7-
y=max(result) #Gets the maximum value in the result list.
8-
return checklist[result.index(y)] #Returns the value with the maximum number of repetitions.
15+
y=max(result) #Gets the maximum value in the result list.
16+
return checklist[result.index(y)] #Returns the value with the maximum number of repetitions.
917
data=[1,2,4,3,1,6,4,2,5,1,1,2,3]
1018
print(mode(data))

0 commit comments

Comments
 (0)