Find existing element
Input
find_index_or_minus_one([1, 2, 3], 2)
Output
1
2 is at index 1 in the list.
Full lesson preview
Find the first index of a target in a list, or return -1 if it isn't present.
Problem statement
Task
Examples
Input
find_index_or_minus_one([1, 2, 3], 2)
Output
1
2 is at index 1 in the list.
Input format
Output format
Constraints
Samples
Input
find_index_or_minus_one([], 'x')
Output
-1
Empty list can't contain 'x', so return -1.