酷代码 AI
菜单
服务商

def find_indices(text, query): # 将文本转换为小写,以实现不区分大小写的搜索 text_lower = text.lower() query_lower = query.lower() start = 0 # 初始化一个列表来存储查询内容的索引 indices = [] # 使用find方法来查找查询内容的索引 while true: start = text_lower.find(query_lower, start) if start == -1: break # 将索引添加到列表中,并更新搜索的起始位置 indices.append(start) start += 1 # 移动到找到的词的下一个字符,以避免重复计数 return indices # 文档内容 document = """ it is

the first paragraph of a document. It contains some information about the document and provides an overview of what is included. The document may also contain other paragraphs, such as a second paragraph or a third paragraph. """ # 要搜索的内容 query = "paragraph" # 调用函数并打印结果 result = find_indices(document, query) print(result) [2024-10-21 21:44:08 | AI写代码神器 | 231点数解答]

相关提问
实用工具查看更多
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]
数独游戏 [娱乐类]
经典推箱子 [娱乐类]
AI摸鱼五子棋 [娱乐类]