def start_when(iterable,p):
s = ''
a = ''
x = iter(iterable)
for x in list(iterable):
a = a + x
try:
while True:
y = next(x)
if p(y) == True:
s = s + a[a.index(y):]
except StopIteration:
pass
return s
start_when生成器将iterable和谓词作为参数:它从iterable中生成每个值,从谓词返回True的第一个值开始 例如:
for i in start_when('combustible', lambda x : x >= 'q’):
print(i,end='')
它打印' ustible'
它给出了以下错误:
21 *Error: ''.join([str(v) for v in start_when('abcdefghijk', lambda x : x >='d')]) raised exception TypeError: 'str' object is not an iterator
22 *Error: ''.join([str(v) for v in start_when(hide('abcdefghijk'), lambda x : x >='d')]) raised exception TypeError: 'str' object is not an iterator
23 *Error: ''.join([str(v) for v in start_when(hide('abcdefghijk'), lambda x : x >'f')]) raised exception TypeError: 'str' object is not an iterator
有人可以帮我解决吗?非常感谢