查找列表中所有出现的子字符串的列表索引
我正在使用Python 3.10。我有一个非常大的清单。列表中的每一项都是 26 个字符的字符串。在这个庞大的列表中的某个地方有一个名字。我想返回该名称的所有出现的列表索引,该名称是字符串中的子字符串。
这是一个名为 alphabet
的简单列表,每个索引处只有一个条目。每个条目都是一个字符串,而我正在寻找的是一个字符串。一切都是大写的,不涉及特殊字符。
我已经看过几件事,但我只能找到返回字符串中子字符串的结果。事实上,它在一个令我困惑的列表中......
I'm using Python 3.10. I have an incredibly large list. Each item in the list is 26 character string. Somewhere within this vast list is a name. I would like to return the list indices of all occurrences of this name, which is a substring within a string.
It's a simple list called alphabet
, with just one entry at each index. Every entry is a string and what I'm looking for is a string. Everything is in uppercase and no special characters are involved.
I've looked at several things but I'm only able to find results for returning substrings within strings. It's the fact that it's in a list that is stumping me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
其中
alphabet
是字符串列表,name
是所需的子字符串。Try this:
where
alphabet
is your list of strings, andname
is the desired substring.