I would like to know if there is a save and fast way of retrieving the index of an element in a list in python 3.
Idea:
# how I do it
try:
test_index = [1,2,3].index(4) # error
except:
# handle error
# how I would like to do it:
test_index = [1,2,3].awesome_index(4) # test_index = -1
if test_index == -1:
# handle error
The reason, why I would like to not use try, except is because try-except appears to be a little bit slower that an if-statement. Since I am handling a lot of data, performance is important to me.
Yes, I know that I could implement awesome_index by simply looping through the list, but I assume that there already is a function doing exactly that in a very efficient way.