I need to create a function that inputs a list of integers and outputs a count of one of three ranges. I know there are easier ways to do it, but this is the way it needs to be done for this project.
let's say the ranges need to be: (x < 10, 10 <= x < 100, x >= 100)
So far I've tried...
list = (1, 2, 10, 20, 50, 100, 200)
low = 0
mid = 0
high = 0
final_list = list()
def func(x):
if x < 10:
low = low + 1
elif x < 100:
mid = mid + 1
else:
high = high + 1
for i in range(len(list)):
x = func(list[i])
final_list.append(x)
This is the best I've been able to come up with, but obviously it's not correct. Again, I realize there are easier ways to accomplish this, but the created function and for loop are required for this specific problem.
So... any ideas?