From 6bb70f4a2d44b9b428685e88a3170ee30a382d6e Mon Sep 17 00:00:00 2001 From: LokiUvaraj <54948079+LokiUvaraj@users.noreply.github.com> Date: Mon, 28 Oct 2019 12:20:54 +0530 Subject: [PATCH 1/8] Add files via upload Finds the mode in the input data. --- maths/average_mode.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 maths/average_mode.py diff --git a/maths/average_mode.py b/maths/average_mode.py new file mode 100644 index 000000000000..96a77b82d4b1 --- /dev/null +++ b/maths/average_mode.py @@ -0,0 +1,11 @@ +def mode(inputlist): + countlist = [] + checklist = inputlist.copy() + result = list() + for x in inputlist: + result.append(inputlist.count(x)) + inputlist.remove(x) + y=max(result) + return checklist[result.index(y)] +data=[1,2,3,4,5,1,1,1,1,1] +print(mode(data)) \ No newline at end of file From 8579199e304e029f18440adb7a1b4103f0648173 Mon Sep 17 00:00:00 2001 From: LokiUvaraj <54948079+LokiUvaraj@users.noreply.github.com> Date: Mon, 28 Oct 2019 12:43:33 +0530 Subject: [PATCH 2/8] Update average_mode.py --- maths/average_mode.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index 96a77b82d4b1..2c3ec1ad7f92 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -1,11 +1,10 @@ -def mode(inputlist): - countlist = [] - checklist = inputlist.copy() - result = list() +def mode(inputlist): #Defining function "mode." + checklist = inputlist.copy() #Copying inputlist to check with the index number later. + result = list() #Empty list to store the counts of elements in inputlist for x in inputlist: - result.append(inputlist.count(x)) + result.append(inputlist.count(x)) inputlist.remove(x) - y=max(result) - return checklist[result.index(y)] -data=[1,2,3,4,5,1,1,1,1,1] -print(mode(data)) \ No newline at end of file + y=max(result) #Gets the maximum value in the result list. + return checklist[result.index(y)] #Returns the value with the maximum number of repetitions. +data=[1,2,4,3,1,6,4,2,5,1,1,2,3] +print(mode(data)) From 9274247c7d915c627f0bcd8e4f1a585ac3cf200f Mon Sep 17 00:00:00 2001 From: LokiUvaraj <54948079+LokiUvaraj@users.noreply.github.com> Date: Mon, 28 Oct 2019 13:21:47 +0530 Subject: [PATCH 3/8] Update average_mode.py --- maths/average_mode.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index 2c3ec1ad7f92..07bcbc8b4fbb 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -1,10 +1,18 @@ -def mode(inputlist): #Defining function "mode." - checklist = inputlist.copy() #Copying inputlist to check with the index number later. - result = list() #Empty list to store the counts of elements in inputlist +def mode(inputlist): #Defining function "mode." + """ + This function returns the mode(Mode as in the measures of central tendency) of the input data. + + >>>mode([2,3,4,5,3,4,2,5,2,2,4,2,2,2]) + 2 + + the input list may contain any Datastructure or any Datatype. + """ + checklist = inputlist.copy() #Copying inputlist to check with the index number later. + result = list() #Empty list to store the counts of elements in inputlist for x in inputlist: result.append(inputlist.count(x)) inputlist.remove(x) - y=max(result) #Gets the maximum value in the result list. - return checklist[result.index(y)] #Returns the value with the maximum number of repetitions. + y=max(result) #Gets the maximum value in the result list. + return checklist[result.index(y)] #Returns the value with the maximum number of repetitions. data=[1,2,4,3,1,6,4,2,5,1,1,2,3] print(mode(data)) From 5a2302bd4a480ef226a61ab1084cad2e29fc9d55 Mon Sep 17 00:00:00 2001 From: LokiUvaraj <54948079+LokiUvaraj@users.noreply.github.com> Date: Mon, 28 Oct 2019 13:32:18 +0530 Subject: [PATCH 4/8] Update average_mode.py --- maths/average_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index 07bcbc8b4fbb..d6f338ae0ffc 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -2,7 +2,7 @@ def mode(inputlist): #Defining function "mode." """ This function returns the mode(Mode as in the measures of central tendency) of the input data. - >>>mode([2,3,4,5,3,4,2,5,2,2,4,2,2,2]) + >>> mode([2,3,4,5,3,4,2,5,2,2,4,2,2,2]) 2 the input list may contain any Datastructure or any Datatype. From 42c11f27dcec381bc8aa4c5488c20bedb9636847 Mon Sep 17 00:00:00 2001 From: LokiUvaraj <54948079+LokiUvaraj@users.noreply.github.com> Date: Mon, 28 Oct 2019 14:48:35 +0530 Subject: [PATCH 5/8] Update average_mode.py --- maths/average_mode.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index d6f338ae0ffc..cb67aad232c6 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -1,18 +1,22 @@ -def mode(inputlist): #Defining function "mode." +def mode(input_list): #Defining function "mode." """ This function returns the mode(Mode as in the measures of central tendency) of the input data. - - >>> mode([2,3,4,5,3,4,2,5,2,2,4,2,2,2]) + + >>> input_list = [2,3,4,5,3,4,2,5,2,2,4,2,2,2] + >>> mode(input_list) 2 + >>> import statistics + >>> mode(input_list) == statistics.mode(input_list) + True the input list may contain any Datastructure or any Datatype. """ - checklist = inputlist.copy() #Copying inputlist to check with the index number later. + check_list = input_list.copy() #Copying inputlist to check with the index number later. result = list() #Empty list to store the counts of elements in inputlist for x in inputlist: - result.append(inputlist.count(x)) - inputlist.remove(x) + result.append(input_list.count(x)) + input_list.remove(x) y=max(result) #Gets the maximum value in the result list. - return checklist[result.index(y)] #Returns the value with the maximum number of repetitions. + return check_list[result.index(y)] #Returns the value with the maximum number of repetitions. data=[1,2,4,3,1,6,4,2,5,1,1,2,3] print(mode(data)) From 04bfa94e0fcd63c11c6a44378b938667259732bd Mon Sep 17 00:00:00 2001 From: LokiUvaraj <54948079+LokiUvaraj@users.noreply.github.com> Date: Mon, 28 Oct 2019 15:45:25 +0530 Subject: [PATCH 6/8] Update average_mode.py --- maths/average_mode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index cb67aad232c6..57eaddf5bf2b 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -13,7 +13,7 @@ def mode(input_list): #Defining function "mode." """ check_list = input_list.copy() #Copying inputlist to check with the index number later. result = list() #Empty list to store the counts of elements in inputlist - for x in inputlist: + for x in input_list: result.append(input_list.count(x)) input_list.remove(x) y=max(result) #Gets the maximum value in the result list. From b4913b977615205be199121aa2a1a6b04c662667 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 30 Oct 2019 00:17:39 +0100 Subject: [PATCH 7/8] Update average_mode.py --- maths/average_mode.py | 47 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index 57eaddf5bf2b..0d1b5ba01ed5 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -1,22 +1,31 @@ -def mode(input_list): #Defining function "mode." - """ - This function returns the mode(Mode as in the measures of central tendency) of the input data. +import statistics + + +def mode(input_list): # Defining function "mode." + """This function returns the mode(Mode as in the measures of + central tendency) of the input data. - >>> input_list = [2,3,4,5,3,4,2,5,2,2,4,2,2,2] - >>> mode(input_list) - 2 - >>> import statistics - >>> mode(input_list) == statistics.mode(input_list) + The input list may contain any Datastructure or any Datatype. + + >>> input_list = [2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2] + >>> mode(input_list) + 2 + >>> input_list = [2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2] + >>> mode(input_list) == statistics.mode(input_list) True - - the input list may contain any Datastructure or any Datatype. """ - check_list = input_list.copy() #Copying inputlist to check with the index number later. - result = list() #Empty list to store the counts of elements in inputlist - for x in input_list: - result.append(input_list.count(x)) - input_list.remove(x) - y=max(result) #Gets the maximum value in the result list. - return check_list[result.index(y)] #Returns the value with the maximum number of repetitions. -data=[1,2,4,3,1,6,4,2,5,1,1,2,3] -print(mode(data)) + # Copying inputlist to check with the index number later. + check_list = input_list[:] + result = list() # Empty list to store the counts of elements in input_list + for x in input_list: + result.append(input_list.count(x)) + input_list.remove(x) + y = max(result) # Gets the maximum value in the result list. + # Returns the value with the maximum number of repetitions. + return check_list[result.index(y)] + + +if __name__ == "__main__": + data = [2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2] + print(mode(data)) + print(statistics.mode(data)) From 7b61def973e5b08c7ee20962dbf1026866e0fae8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Wed, 30 Oct 2019 00:23:14 +0100 Subject: [PATCH 8/8] Tabs do not belong in Python files! --- maths/average_mode.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maths/average_mode.py b/maths/average_mode.py index 0d1b5ba01ed5..c1a4b3521448 100644 --- a/maths/average_mode.py +++ b/maths/average_mode.py @@ -12,10 +12,10 @@ def mode(input_list): # Defining function "mode." 2 >>> input_list = [2, 3, 4, 5, 3, 4, 2, 5, 2, 2, 4, 2, 2, 2] >>> mode(input_list) == statistics.mode(input_list) - True - """ + True + """ # Copying inputlist to check with the index number later. - check_list = input_list[:] + check_list = input_list.copy() result = list() # Empty list to store the counts of elements in input_list for x in input_list: result.append(input_list.count(x))