Is there any way to assign operators to variables? I have function
def get_age(age=0, year_level_from=0, year_level_to=0):
overall = []
for level in range(year_level_from, year_level_to):
if age <= 11:
operator = <=
else:
operator = >=
male_count = len([
info for info in queryset
if info.age **operator** age
if info.gender == 'male'
if info.year_level == level
])
overall.append(male_count)
I want to declare like get_age(age=11, year_level_from=1, year_level_to=7) if this is possible so this function have the ability to choose those age with that condition I want to get. thanks in advance