我在写一个简单的搜索算法。以下是我的代码。替代Len函数
def search(list_data,target_char):
found = False
position = 0
while position < len(list_data) and not found:
if list_data[position] == target_char:
found = True
position += 1
return found
但是我不应该使用len()或任何其他内置函数。我怎么能这样做?
'而真实:... break'?你还需要像你一样手动增加位置,并且需要一个'try-except'块来捕捉'IndexError' –