以下是一个使用 Python 实现的简单文档内容查询程序示例,用于查找文档中特定内容的索引: ```python def search_document(document, target): indices = [] words = document.split() for i, word in enumerate(words): if word == target: indices.append(i) return indices document = "it is not the critic who counts, not the man who points out how the strong man stumbles, the doer of deeds could have done them better. the credit belongs to the man who is actually in the are 'ns, whose face is marred by dust and sweat and blood; who strives valiantly; who errs, and comes short again and again ;because there is not effort without error and shortcoming; but who does actually strive to do the deeds; who knows the great enthusiasms, the gre" target = "the" print(search_document(document, target)) ``` 在上述示例中,我们定义了一个 `search_document` 函数,它接受文档内容和要查找的目标字符串作为参数,通过将文档分割为单词,然后遍历每个单词来查找目标字符串出现的索引,并将其存储在一个列表中返回。 [2024-10-22 15:37:39 | AI写代码神器 | 261点数解答]