Skip to content

Commit 42c11f2

Browse files
authored
Update average_mode.py
1 parent 5a2302b commit 42c11f2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

maths/average_mode.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
1-
def mode(inputlist): #Defining function "mode."
1+
def mode(input_list): #Defining function "mode."
22
"""
33
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])
4+
5+
>>> input_list = [2,3,4,5,3,4,2,5,2,2,4,2,2,2]
6+
>>> mode(input_list)
67
2
8+
>>> import statistics
9+
>>> mode(input_list) == statistics.mode(input_list)
10+
True
711
812
the input list may contain any Datastructure or any Datatype.
913
"""
10-
checklist = inputlist.copy() #Copying inputlist to check with the index number later.
14+
check_list = input_list.copy() #Copying inputlist to check with the index number later.
1115
result = list() #Empty list to store the counts of elements in inputlist
1216
for x in inputlist:
13-
result.append(inputlist.count(x))
14-
inputlist.remove(x)
17+
result.append(input_list.count(x))
18+
input_list.remove(x)
1519
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.
20+
return check_list[result.index(y)] #Returns the value with the maximum number of repetitions.
1721
data=[1,2,4,3,1,6,4,2,5,1,1,2,3]
1822
print(mode(data))

0 commit comments

Comments
 (0)