As Aaron states, you can use .index(value)
, but because that will throw an exception if value
is not present, you should handle that case, even if you're sure it will never happen. A couple options are by checking its presence first, such as:
if value in my_list:
value_index = my_list.index(value)
or by catching the exception as in:
try:
value_index = my_list.index(value)
except:
value_index = -1
You can never go wrong with proper error handling.