Números de filtro com limites filtro_bounds python
def select_within_bounds(li, lower=None, upper=None):
if lower is None:
if upper is None:
return li
else:
return [v for v in li if v <= upper]
else:
if upper is None:
return [v for v in li if v >= lower]
else:
return [v for v in li if lower <= v <= upper]
#example:
my_list = [1, 4, 5, 3, 6, 9]
print(select_within_bounds(my_list))
print(select_within_bounds(my_list, 3, 8))
print(select_within_bounds(my_list, lower=3))
print(select_within_bounds(my_list, upper=8))
print(select_within_bounds(my_list, lower=3,upper=8))
#results in
[1, 4, 5, 3, 6, 9]
[4, 5, 3, 6]
[4, 5, 3, 6, 9]
[1, 4, 5, 3, 6]
[4, 5, 3, 6]
Horrible Hoopoe