[英]Find all instances of a sub-string in a list of strings and return the index of the string where the sub-string is found
[英]How to find start & end index of a sub-string from a string
我正在尝试获取子字符串的开始和结束位置
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]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.