The list a
below prints all the items in between 0 and 5:
[1, 2, 3, 2, 3]
a = [100, 1, 10, 2, 3, 5, 8, 13, 2, 3, 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)
How can I print the sub-list where the items are in between 0 and 5 inclusive, and if the item falls out of the range, start a new sub-list?
Expected output:
[1], [2,3,5], [2,3]