def make_sequence(seq):
def filter1(*func):
new_filter = filter(func, seq)
return tuple(new_filter)
def filter_iterator(*func):
new_seq = tuple(filter(func, seq))
index = 0
def next1():
nonlocal index
if index >= 0 and index < len(new_seq):
ele = new_seq[index]
index += 1
else:
index = 0
ele = new_seq[index]
index += 1
return ele
def reverse():
nonlocal index
index -= 1
if index >= 0 and index < len(new_seq):
ele = new_seq[index]
else:
index = len(new_seq) - 1
ele = new_seq[index]
return ele
return {'next': next1, 'reverse': reverse}
def reverse():
return tuple(seq[::-1])
def extend(new_seq):
nonlocal seq
seq += new_seq
return {'filter': filter1, 'filter_iterator': filter_iterator, 'reverse': reverse, 'extend': extend}
s1 = make_sequence((1, 2, 3, 4, 5))
print(s1['filter'](lambda x: x % 2 == 0))
When I try to return tuple from fitlter1 I get the error:
'tuple' object is not callable.
What I try to do is the filter1 get the argument *args because when I will call filiter1() with nothing function he returns the sequence without change.