#i want to pass the list, and algorithm (bubblesort) into the sort method with a requirement (temp or wind_speed)
class Reading:
def __init__(self, _temperature, _windspeed):
self.temp = _temperature
self.windspeed = _windspeed
def bubblesort(num):
for i in range (len(num)-1, 0, -1):
for j in range (i):
if num[j] > num [j+1] :
temp = num[j]
num[j] = num[j+1]
num[j+1] = temp
return num
r_list = [Reading(randint(10, 60), randint(10, 60)) for i in range(20)]
def sort(lst, alg): #how do i pass the requirement, and alg?
bubblesort(lst)
sort(r_list, alg) #how do i create a templated bubblesort to either sort temp or windspeed?
#The Output is supposed to return a sorted list (r_list) according to the requirement
Here's an example how to pass a function as an argument to another function: