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...
Try this:
indices = [idx for idx, s in enumerate(alphabet) if name in s]
where alphabet
is your list of strings, and name
is the desired substring.