def filter_list(elements):
data = [elements]
for a in elements:
if a == (int(a) or float(a)) and a >= 1 and a < 50:
return "true"
else:
return "false"
filter_list([1, 2, 3])
filter_list([0, 2, 3])
filter_list([1, 50, 3])
This function searches if int or floats between 1 and 50 are in the list. But it only searches the first list entry. How can i expand the search on the whole list? Also if i write 1.1 in the list, the result will be False.
filter_list([1, 2, 3]) = True
filter_list([0, 2, 3]) = False
filter_list([1, 50, 3]) = True (which should be False)
filter_list([1.1, 2, 3]) = False (which should be True)
Edited:
def filter_list(elements):
data = [elements]
for a in elements:
if a == int(a) and a >= 1 and a < 50:
filter = []
filter.append(a)
return filter
filter_list([2, 1, 4, 5, 6])
This results in [6], which i dont want to.