In the specific case, when your list is a sequence of one-character strings, you can get what you want by changing the list to search in the string in advance (for example. '.Join (chars)).
Then you can use the .find () method, which works the way you want. However, there is no appropriate method for lists or tuples.
Another possible option is to use a dictionary. eg.
d = dict((x, loc) for (loc,x) in enumerate(chars)) ... index = d.get(chars_to_find, -1) # Second argument is default if not found.
It can also improve if you are doing a lot of queries on the list. If this is just one search on the list, but it is not worth doing.
Brian source share