def start_when(iterable,p):
s = ''
a = ''
x = iter(iterable)
for y in x:
a = a + y
try:
for y in x:
if p(y) == True:
s = s + a[a.index(y):]
break
except StopIteration:
pass
return s
The start_when generator takes an iterable and a predicate as parameters: it produces every value from the iterable, starting with the first value for which the predicate returns True
for example:
for i in start_when('combustible', lambda x : x >= 'q’):
print(i,end='')
it prints
ustible
however, when my function takes input
('abcdefghijk', lambda x : x >='d')])
it should return
defghijk
But it returns nothing instead
below it the error I got:
21 *Error: ''.join([str(v) for v in start_when('abcdefghijk', lambda x : x >='d')]) -> but should -> defghijk
22 *Error: ''.join([str(v) for v in start_when(hide('abcdefghijk'), lambda x : x >='d')]) -> but should -> defghijk
23 *Error: ''.join([str(v) for v in start_when(hide('abcdefghijk'), lambda x : x >'f')]) -> but should -> ghijk
can someone help me to fix my function? Many thanks!