python - 如何从字符串中查找子字符串的开始和结束索引
问题描述
我正在尝试获取子字符串的开始和结束位置
mystr = "I live at 2 Inchydoney Island. Inchydoney, Co Cork"
search_str = '2 Inchydoney Island. Inchydoney, Co Cork'
result = [i+1 for i,w in enumerate(mystr.split()) if w.lower() == search_str]
print(result)
我尝试了一段代码,但它没有返回任何内容。
预期产出
[11,48]
解决方案
推荐阅读
- javascript - 仅更新 IndexedDB 中对象的某些字段
- hibernate - 如何在 JPA 中使用过滤列表过滤列表属性?
- amazon-web-services - 如何启用 AWS RDS 审计日志并将选项组关联到 RDS 实例
- c++ - 编写正则表达式模式 C++
- r - R中的状态变化
- python - 我想按今天过滤并计算当天的 id
- java - 基于 Cache-Control Headers 和 Feign 客户端的缓存
- c++ - 当我链接两个静态库时,我可以在 C++ 的两个静态库中有两个主要功能吗?
- automation - 为什么鼠标的位置总是取绝对位置,而位置命令的颜色总是返回窗口的相对颜色?
- sorting - 如何对嵌套的 ObjectData Flutter 进行排序