'Function missing a positional argument
I've got the code below that is giving me the following error: bubble_sort() missing 1 required positional argument: 'a_list'. I am passing a list to the function, so I do not know where the error is coming from. I am learning python right now, so understanding what I am doing wrong and the why is important to me.
import functools
import time
def sort_timer(func):
"""
Timer function that counts how many seconds it takes the decoration function to run, in this case the sort functions
described above. Returns the number of seconds using the time module.
:param func:
:return total_time:
"""
@functools.wraps(func)
def wrapper(*args, **kwargs):
"""
Calculates the total time a function runs.
:return:
"""
total_time = None
start_time = time.perf_counter()
func(*args, **kwargs)
end_time = time.perf_counter()
local_total_time = end_time - start_time
return total_time
return wrapper()
@sort_timer
def bubble_sort(a_list):
"""
Sorts a_list in ascending order
"""
for pass_num in range(len(a_list) - 1):
for index in range(len(a_list) - 1 - pass_num):
if a_list[index] > a_list[index + 1]:
temp = a_list[index]
a_list[index] = a_list[index + 1]
a_list[index + 1] = temp
def main():
random_list = [5,1,10,15,3,6,45,21,90, 76,44,33,41,27,81]
print(bubble_sort(random_list))
if __name__ == "__main__":
main()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
