Loop through a list and create a new list with specific items
a = [100, 1, 10, 2, 3, 5, 8, 13, 21, 34, 55, 98] def new_list(x): new = [] for item in range(len(x)): if x[item] < 5 and x[item] > 0: new.append(x[item]) return new print(new_list(a))
Output
[1, 2, 3]